{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/Users/utensil/Library/Jupyter/runtime/kernel-28d6ca25-a548-4761-a6ed-7b0076c765b8.json\n"
     ]
    }
   ],
   "source": [
    "for x in ARGS; println(x); end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Greetings! 你好! 안녕하세요?\n"
     ]
    }
   ],
   "source": [
    "println(\"Greetings! 你好! 안녕하세요?\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "julia [switches] -- [programfile] [args...]\n",
      " -v, --version             Display version information\n",
      " -h, --help                Print this message\n",
      "\n",
      " -J, --sysimage <file>     Start up with the given system image file\n",
      " --precompiled={yes|no}    Use precompiled code from system image if available\n",
      " -H, --home <dir>          Set location of julia executable\n",
      " --startup-file={yes|no}   Load ~/.juliarc.jl\n",
      " -f, --no-startup          Don't load ~/.juliarc (deprecated, use --startup-file=no)\n",
      " -F                        Load ~/.juliarc (deprecated, use --startup-file=yes)\n",
      " --handle-signals={yes|no} Enable or disable Julia's default signal handlers\n",
      "\n",
      " -e, --eval <expr>         Evaluate <expr>\n",
      " -E, --print <expr>        Evaluate and show <expr>\n",
      " -P, --post-boot <expr>    Evaluate <expr>, but don't disable interactive mode (deprecated, use -i -e instead)\n",
      " -L, --load <file>         Load <file> immediately on all processors\n",
      "\n",
      " -p, --procs {N|auto}      Integer value N launches N additional local worker processes\n",
      "                           \"auto\" launches as many workers as the number of local cores\n",
      " --machinefile <file>      Run processes on hosts listed in <file>\n",
      "\n",
      " -i                        Interactive mode; REPL runs and isinteractive() is true\n",
      " -q, --quiet               Quiet startup (no banner)\n",
      " --color={yes|no}          Enable or disable color text\n",
      " --history-file={yes|no}   Load or save history\n",
      " --no-history-file         Don't load history file (deprecated, use --history-file=no)\n",
      "\n",
      " --compile={yes|no|all}    Enable or disable compiler, or request exhaustive compilation\n",
      " -C, --cpu-target <target> Limit usage of cpu features up to <target>\n",
      " -O, --optimize            Run time-intensive code optimizations\n",
      " --inline={yes|no}         Control whether inlining is permitted (overrides functions declared as @inline)\n",
      " --check-bounds={yes|no}   Emit bounds checks always or never (ignoring declarations)\n",
      " --math-mode={ieee,fast}   Disallow or enable unsafe floating point optimizations (overrides @fastmath declaration)\n",
      "\n",
      " --depwarn={yes|no|error}  Enable or disable syntax and method deprecation warnings (\"error\" turns warnings into errors)\n",
      "\n",
      " --output-o name           Generate an object file (including system image data)\n",
      " --output-ji name          Generate a system image data file (.ji)\n",
      " --output-bc name          Generate LLVM bitcode (.bc)\n",
      "\n",
      " --output-incremental=no   Generate an incremental output file (rather than complete)\n",
      "\n",
      " --code-coverage={none|user|all}, --code-coverage\n",
      "                           Count executions of source lines (omitting setting is equivalent to \"user\")\n",
      " --track-allocation={none|user|all}, --track-allocation\n",
      "                           Count bytes allocated by each source line\n"
     ]
    }
   ],
   "source": [
    "run(`julia --help`)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"idea\""
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "理念=\"idea\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "idea\n"
     ]
    }
   ],
   "source": [
    "println(\"$理念\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "π = 3.1415926535897..."
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "π"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "From __Variables: Stylistic Conventions__\n",
    "\n",
    "While Julia imposes few restrictions on valid names, it has become useful to adopt the following conventions:\n",
    "\n",
    "* Names of variables are in lower case.\n",
    "* Word separation can be indicated by underscores (`'_'`), but use of underscores is discouraged unless the name would be hard to read otherwise.\n",
    "* Names of `Type`s and `Module`s begin with a capital letter and word separation is shown with upper camel case instead of underscores.\n",
    "* Names of `function`s and `macro`s are in lower case, without underscores.\n",
    "* Functions that write to their arguments have names that end in `!`. These are sometimes called “mutating” or “in-place” functions because they are intended to produce changes in their arguments after the function is called, not just return a value."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "64"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "WORD_SIZE"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "UInt64"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "UInt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Int64"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "typeof(WORD_SIZE)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Irrational{:π}"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "typeof(π)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0x02"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "0b10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0x08"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "0o10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   Int8: [-128,127]\n",
      "  Int16: [-32768,32767]\n",
      "  Int32: [-2147483648,2147483647]\n",
      "  Int64: [-9223372036854775808,9223372036854775807]\n",
      " Int128: [-170141183460469231731687303715884105728,170141183460469231731687303715884105727]\n",
      "  UInt8: [0,255]\n",
      " UInt16: [0,65535]\n",
      " UInt32: [0,4294967295]\n",
      " UInt64: [0,18446744073709551615]\n",
      "UInt128: [0,340282366920938463463374607431768211455]\n"
     ]
    }
   ],
   "source": [
    "for T in [Int8,Int16,Int32,Int64,Int128,UInt8,UInt16,UInt32,UInt64,UInt128]\n",
    "    println(\"$(lpad(T,7)): [$(typemin(T)),$(typemax(T))]\")\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "typemax(Int64) + 1 == typemin(Int64)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "typemax(UInt64) + 1 == typemin(UInt64)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "LoadError",
     "evalue": "LoadError: DivideError: integer division error\nwhile loading In[19], in expression starting on line 1",
     "output_type": "error",
     "traceback": [
      "LoadError: DivideError: integer division error\nwhile loading In[19], in expression starting on line 1",
      "",
      " in div at /opt/homebrew-cask/Caskroom/julia/0.4.5/Julia-0.4.5.app/Contents/Resources/julia/lib/julia/sys.dylib"
     ]
    }
   ],
   "source": [
    "div(typemax(Int64), 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-9223372036854775808"
     ]
    },
    {
     "ename": "LoadError",
     "evalue": "LoadError: DivideError: integer division error\nwhile loading In[21], in expression starting on line 2",
     "output_type": "error",
     "traceback": [
      "LoadError: DivideError: integer division error\nwhile loading In[21], in expression starting on line 2",
      "",
      " in div at /opt/homebrew-cask/Caskroom/julia/0.4.5/Julia-0.4.5.app/Contents/Resources/julia/lib/julia/sys.dylib"
     ]
    }
   ],
   "source": [
    "@printf \"%ld\" typemin(Int64)\n",
    "div(typemin(Int64), -1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "0x.1p0 == (1.0/16.0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "0x.1p1 == (1.0/16.0) * 2^1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sizeof(0x.1p0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.0"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1/Inf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sizeof(Inf)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "NaN"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "0/0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Inf"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2 * Inf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Inf"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Inf^Inf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "NaN"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Inf / Inf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "NaN"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "0 * Inf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(-Inf,Inf)"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(typemin(Float64),typemax(Float64))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1.1920929f-7,2.220446049250313e-16,5.36870912e8)"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "eps(Float32),eps(Float64), eps(Float32) / eps(Float64)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "LoadError",
     "evalue": "LoadError: MethodError: `nextfloat` has no method matching nextfloat(::Irrational{:π})\nwhile loading In[57], in expression starting on line 1",
     "output_type": "error",
     "traceback": [
      "LoadError: MethodError: `nextfloat` has no method matching nextfloat(::Irrational{:π})\nwhile loading In[57], in expression starting on line 1",
      ""
     ]
    }
   ],
   "source": [
    "nextfloat(π)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3.1415926530000005"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nextfloat(3.141592653)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.2000000000000002"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1.1 + 0.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.2"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "with_rounding(Float64,RoundDown) do\n",
    "    1.1 + 0.1\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "false"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1.1 + 0.1 == with_rounding(Float64,RoundDown) do\n",
    "    1.1 + 0.1\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "113868781241213194875412146"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "BigInt(typemax(Int64))*BigInt(12345678)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.234567890123456789010000000000000000000000000000000000000000000000000000000004"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "parse(BigFloat, \"1.23456789012345678901\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3.141592653589793238462643383279502884197169399375105820974944592307816406286198"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "BigFloat(π)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "815915283247897734345611269596115894272000000000"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "factorial(BigInt(40))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{verbatim}\n",
       "..  factorial(n,k)\n",
       "\n",
       "Compute ``factorial(n)/factorial(k)``\n",
       "\\end{verbatim}\n",
       "\\begin{verbatim}\n",
       "..  factorial(n)\n",
       "\n",
       "Factorial of ``n``.  If ``n`` is an :obj:`Integer`, the factorial\n",
       "is computed as an integer (promoted to at least 64 bits).  Note\n",
       "that this may overflow if ``n`` is not small, but you can use\n",
       "``factorial(big(n))`` to compute the result exactly in arbitrary\n",
       "precision.  If ``n`` is not an ``Integer``, ``factorial(n)`` is\n",
       "equivalent to :func:`gamma(n+1) <gamma>`.\n",
       "\\end{verbatim}\n"
      ],
      "text/markdown": [
       "```rst\n",
       "..  factorial(n,k)\n",
       "\n",
       "Compute ``factorial(n)/factorial(k)``\n",
       "```\n",
       "\n",
       "```rst\n",
       "..  factorial(n)\n",
       "\n",
       "Factorial of ``n``.  If ``n`` is an :obj:`Integer`, the factorial\n",
       "is computed as an integer (promoted to at least 64 bits).  Note\n",
       "that this may overflow if ``n`` is not small, but you can use\n",
       "``factorial(big(n))`` to compute the result exactly in arbitrary\n",
       "precision.  If ``n`` is not an ``Integer``, ``factorial(n)`` is\n",
       "equivalent to :func:`gamma(n+1) <gamma>`.\n",
       "```\n"
      ],
      "text/plain": [
       "```rst\n",
       "..  factorial(n,k)\n",
       "\n",
       "Compute ``factorial(n)/factorial(k)``\n",
       "```\n",
       "\n",
       "```rst\n",
       "..  factorial(n)\n",
       "\n",
       "Factorial of ``n``.  If ``n`` is an :obj:`Integer`, the factorial\n",
       "is computed as an integer (promoted to at least 64 bits).  Note\n",
       "that this may overflow if ``n`` is not small, but you can use\n",
       "``factorial(big(n))`` to compute the result exactly in arbitrary\n",
       "precision.  If ``n`` is not an ``Integer``, ``factorial(n)`` is\n",
       "equivalent to :func:`gamma(n+1) <gamma>`.\n",
       "```\n"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@doc factorial"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2x^2 - 3x + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "13.0"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1.5x^2 - .5x + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "64"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2^2x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(2^2)x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Int8:\n",
      "\tzero:               \t0\n",
      "\tone:                \t1\n",
      "\ttypemin:            \t-128\n",
      "\ttypemax:            \t127\n",
      "Int16:\n",
      "\tzero:               \t0\n",
      "\tone:                \t1\n",
      "\ttypemin:            \t-32768\n",
      "\ttypemax:            \t32767\n",
      "Int32:\n",
      "\tzero:               \t0\n",
      "\tone:                \t1\n",
      "\ttypemin:            \t-2147483648\n",
      "\ttypemax:            \t2147483647\n",
      "Int64:\n",
      "\tzero:               \t0\n",
      "\tone:                \t1\n",
      "\ttypemin:            \t-9223372036854775808\n",
      "\ttypemax:            \t9223372036854775807\n",
      "Int128:\n",
      "\tzero:               \t0\n",
      "\tone:                \t1\n",
      "\ttypemin:            \t-170141183460469231731687303715884105728\n",
      "\ttypemax:            \t170141183460469231731687303715884105727\n",
      "UInt8:\n",
      "\tzero:               \t0\n",
      "\tone:                \t1\n",
      "\ttypemin:            \t0\n",
      "\ttypemax:            \t255\n",
      "UInt16:\n",
      "\tzero:               \t0\n",
      "\tone:                \t1\n",
      "\ttypemin:            \t0\n",
      "\ttypemax:            \t65535\n",
      "UInt32:\n",
      "\tzero:               \t0\n",
      "\tone:                \t1\n",
      "\ttypemin:            \t0\n",
      "\ttypemax:            \t4294967295\n",
      "UInt64:\n",
      "\tzero:               \t0\n",
      "\tone:                \t1\n",
      "\ttypemin:            \t0\n",
      "\ttypemax:            \t18446744073709551615\n",
      "UInt128:\n",
      "\tzero:               \t0\n",
      "\tone:                \t1\n",
      "\ttypemin:            \t0\n",
      "\ttypemax:            \t340282366920938463463374607431768211455\n",
      "BigInt:\n",
      "\tzero:               \t0\n",
      "\tone:                \t1\n",
      "Float16:\n",
      "\tzero:               \t0.0\n",
      "\tone:                \t1.0\n",
      "\ttypemin:            \t-Inf\n",
      "\ttypemax:            \tInf\n",
      "Float32:\n",
      "\tzero:               \t0.0\n",
      "\tone:                \t1.0\n",
      "\ttypemin:            \t-Inf\n",
      "\ttypemax:            \tInf\n",
      "Float64:\n",
      "\tzero:               \t0.0\n",
      "\tone:                \t1.0\n",
      "\ttypemin:            \t-Inf\n",
      "\ttypemax:            \tInf\n",
      "BigFloat:\n",
      "\tzero:               \t0.000000000000000000000000000000000000000000000000000000000000000000000000000000\n",
      "\tone:                \t1.000000000000000000000000000000000000000000000000000000000000000000000000000000\n",
      "\ttypemin:            \t-inf\n",
      "\ttypemax:            \tinf\n"
     ]
    }
   ],
   "source": [
    "print_type_info(T) = begin\n",
    "    const COLUME_WIDTH = 20\n",
    "    # TODO %s can't preserve literal\n",
    "    @printf \"%s:\\n\" T\n",
    "    @printf \"\\t%s\\t%s\\n\" rpad(\"zero:\",COLUME_WIDTH) zero(T)\n",
    "    @printf \"\\t%s\\t%s\\n\" rpad(\"one:\",COLUME_WIDTH) one(T)\n",
    "    try\n",
    "        @printf \"\\t%s\\t%s\\n\" rpad(\"typemin:\",COLUME_WIDTH) typemin(T)\n",
    "        @printf \"\\t%s\\t%s\\n\" rpad(\"typemax:\",COLUME_WIDTH) typemax(T)\n",
    "    catch e\n",
    "        # do nothing\n",
    "    end\n",
    "end\n",
    "    \n",
    "for t in [Int8,Int16,Int32,Int64,Int128,UInt8,UInt16,UInt32,UInt64,UInt128,BigInt]\n",
    "    print_type_info(t)\n",
    "end\n",
    "for t in [Float16,Float32,Float64,BigFloat]\n",
    "    print_type_info(t)\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0f0"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "one(Float32)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "one(Float64)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.5"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1 / 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Float64"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "typeof(1 / 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.5"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2 \\ 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "100 % 33"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"0101010101010101\""
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bits(~0b1010101010101010)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"00000010\""
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bits(0b11 & 0b10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"00000011\""
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bits(0b11 | 0b10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"00000110\""
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bits(0b1010 $ 0b1100) # xor"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1 >> 2 == 1 >>> 2 # TODO what's the difference?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "isequal(1 >> 2, 1 >>> 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1 < 2 <= 2 < 3 == 3 > 2 >= 1 == 1 < 3 != 5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3.1415927f0"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Float32(π)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3.141592653589793"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Float64(π)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cos(1 + 2im) == cos(complex(1, 2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Inf + NaN*im"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "complex(Inf, NaN)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Rational{Int64}"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "typeof(2//3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "0.33 < 1//3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"Hello, world.\\n\""
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str = \"Hello, world.\\n\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\n'"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str[end]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "' '"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str[end÷2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'l'"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str[end÷3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"lo, \""
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str[end÷3:end÷2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"∀ x ∃ y\""
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = \"\\u2200 x \\u2203 y\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "∀\n",
      " \n",
      "x\n",
      " \n",
      "∃\n",
      " \n",
      "y\n"
     ]
    }
   ],
   "source": [
    "for i = 1:endof(s)\n",
    "    try\n",
    "        println(s[i])\n",
    "    catch\n",
    "        # ignore the index error\n",
    "    end\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "∀\n",
      " \n",
      "x\n",
      " \n",
      "∃\n",
      " \n",
      "y\n"
     ]
    }
   ],
   "source": [
    "for c in s\n",
    "    println(c)\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "language=\"Julia\"\n",
    "\"Hello $language\\!\" == string(\"Hello \", language, \"!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"1 + 2 = 3\""
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"1 + 2 = $(1 + 2)\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"  Hello,\\n  Julia.\\n\""
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str = \"\"\"\n",
    "   Hello,\n",
    "   $language.\n",
    " \"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n",
      "7\n",
      "0\n"
     ]
    }
   ],
   "source": [
    "last_index = -1\n",
    "while last_index != 0\n",
    "    last_index = last_index < 0 ? search(\"xylophone\", 'o') : search(\"xylophone\", 'o', last_index + 1)\n",
    "    @printf \"%d\\n\" last_index\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\".:Z:..:Z:..:Z:..:Z:..:Z:..:Z:..:Z:..:Z:..:Z:..:Z:.\""
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "repeat(\".:Z:.\", 10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"apples, bananas, pear and pineapples\""
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "join([\"apples\", \"bananas\", \"pear\", \"pineapples\"], \", \", \" and \")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "r\"^\\s*(?:#|$)\""
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "regex = r\"^\\s*(?:#|$)\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "false"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ismatch(regex, \"not a comment\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ismatch(regex, \"# a comment\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Regex"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "typeof(regex)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RegexMatch(\"# a comment\", 1=\"a comment\")"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m = match(r\"^\\s*(?:#\\s*(.*?)\\s*$|$)\", \"# a comment\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"a comment\""
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"# a comment\""
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m.match"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1-element Array{Union{SubString{UTF8String},Void},1}:\n",
       " \"a comment\""
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m.captures"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1-element Array{Int64,1}:\n",
       " 3"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m.offsets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"second first third\""
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "replace(\"first second third\", r\"^(\\w+) (?P<agroup>\\w+)\", s\"\\g<agroup> \\1\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"first third second\""
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "replace(\"first second third\", r\"(\\w+) (?P<agroup>\\w+)$\", s\"\\g<agroup> \\1\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8-element Array{UInt8,1}:\n",
       " 0x44\n",
       " 0x41\n",
       " 0x54\n",
       " 0x41\n",
       " 0xff\n",
       " 0xe2\n",
       " 0x88\n",
       " 0x80"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b\"DATA\\xff\\u2200\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"00000000000000000010001000000000\""
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bits('\\u2200')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"00000000000000000010001000000000\""
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bits('\\xe2\\x88\\x80')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "f (generic function with 1 method)"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "function f(x,y)\n",
    "  x + y\n",
    "end\n",
    " ∑ = f"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f(2, 3) ==  ∑(2, 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "hypot (generic function with 1 method)"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "function hypot(x,y)\n",
    "  x = abs(x)\n",
    "  y = abs(y)\n",
    "  if x > y\n",
    "    r = y/x\n",
    "    return x*sqrt(1+r*r)\n",
    "  end\n",
    "  if y == 0\n",
    "    return zero(x)\n",
    "  end\n",
    "  r = x/y\n",
    "  return y*sqrt(1+r*r)\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5.0"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hypot(3, 4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "+(1,2,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fadd = +\n",
    "fadd(1, 2, 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1x3 Array{Int64,2}:\n",
       " 1  2  3"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[1 2 3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3-element Array{Int64,1}:\n",
       " 1\n",
       " 2\n",
       " 3"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[1, 2, 3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3x2 Array{Int64,2}:\n",
       " 1  2\n",
       " 3  4\n",
       " 5  6"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[1 2; 3 4; 5 6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hcat(1, 2, 3) == [1 2 3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vcat(1, 2, 3) == [1, 2, 3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hvcat( (2, 2, 2) , 1, 2, 3, 4, 5, 6) == [1 2; 3 4; 5 6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hvcat(2, 1, 2, 3, 4, 5, 6) == [1 2; 3 4; 5 6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3x2 Array{Complex{Int64},2}:\n",
       " 1+0im  0+2im\n",
       " 0+3im  4+0im\n",
       " 5+0im  0+6im"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mx = [1 2im; 3im 4; 5 6im]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2x3 Array{Complex{Int64},2}:\n",
       " 1+0im  0-3im  5+0im\n",
       " 0-2im  4+0im  0-6im"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mx'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2x3 Array{Complex{Int64},2}:\n",
       " 1+0im  0+3im  5+0im\n",
       " 0+2im  4+0im  0+6im"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mx.'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1:100 == colon(1, 100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# See Functions: Operators With Special Names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(anonymous function)"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x -> x^2 + 2x - 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(anonymous function)"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "function (x)\n",
    "   x^2 + 2x - 1\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3-element Array{Int64,1}:\n",
       "  2\n",
       " 14\n",
       " -2"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "map(x -> x^2 + 2x - 1, [1,3,-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(5,6)"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "function foo(a,b)\n",
    "    a+b, a*b\n",
    "end\n",
    "foo(2, 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1,2,(3,4,5,6))"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bar(a,b,x...) = (a,b,x)\n",
    "bar(1,2,3,4,5,6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "baz(a,b) = a + b\n",
    "args = [1,2]\n",
    "baz(args...)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "function bonus_add(a, b, c=5)\n",
    "    a + b + c\n",
    "end\n",
    "bonus_add(2, 3) == bonus_add(2, 3, 5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "function extra_add(a; b=3, c=5)\n",
    "    a + b + c\n",
    "end\n",
    "extra_add(2, b=4, c=4) == extra_add(0, b=5) == extra_add(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "map(x->begin\n",
    "           if x < 0 && iseven(x)\n",
    "               return 0\n",
    "           elseif x == 0\n",
    "               return 1\n",
    "           else\n",
    "               return x\n",
    "           end\n",
    "       end,\n",
    "[1, 2, 3]) == map([1, 2, 3]) do x # Am I writing ruby? ^_^\n",
    "    if x < 0 && iseven(x)\n",
    "        return 0\n",
    "    elseif x == 0\n",
    "        return 1\n",
    "    else\n",
    "        return x\n",
    "    end\n",
    "end # The do x syntax creates an anonymous function with argument x and passes it as the first argument"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "begin\n",
    "    x = 1\n",
    "    y = 2\n",
    "    x + y\n",
    "end == (x = 1; y = 2; x + y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Although it is typical, there is no requirement that begin blocks be multiline or that (;) chains be single-line\n",
    "begin x = 1; y = 2; x + y end == (x = 1;\n",
    "        y = 2;\n",
    "        x + y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "test_order (generic function with 1 method)"
      ]
     },
     "execution_count": 105,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "function test_order(x, y)\n",
    " if x < y\n",
    "   println(\"$x is less than $y\")\n",
    " elseif x > y\n",
    "   println(\"$x is greater than $y\")\n",
    " else\n",
    "   println(\"$x is equal to $y\")\n",
    " end\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 is less than 3\n"
     ]
    }
   ],
   "source": [
    "test_order(1, 3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`if` blocks are “leaky”, i.e. they do not introduce a local scope. This means that new variables defined inside the `ìf` clauses can be used after the `if` block, even if they weren’t defined before. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "test_order_leaky (generic function with 1 method)"
      ]
     },
     "execution_count": 107,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "function test_order_leaky(x,y)\n",
    " if x < y\n",
    "   relation = \"less than\"\n",
    " elseif x == y\n",
    "   relation = \"equal to\"\n",
    " end\n",
    " println(\"$x is \", relation, \" $y.\")\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 is less than 3.\n"
     ]
    }
   ],
   "source": [
    "test_order_leaky(1, 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "LoadError",
     "evalue": "LoadError: UndefVarError: relation not defined\nwhile loading In[111], in expression starting on line 1",
     "output_type": "error",
     "traceback": [
      "LoadError: UndefVarError: relation not defined\nwhile loading In[111], in expression starting on line 1",
      "",
      " in test_order_leaky at In[107]:7"
     ]
    }
   ],
   "source": [
    "test_order_leaky(11, 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5 > 1\n"
     ]
    }
   ],
   "source": [
    "5 > 1 && println(\"5 > 1\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "false\n"
     ]
    }
   ],
   "source": [
    "4 < 1 || println(\"false\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n"
     ]
    }
   ],
   "source": [
    "i = 1\n",
    "while i <= 5\n",
    " println(i)\n",
    " i += 1\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n"
     ]
    }
   ],
   "source": [
    "for j=1:5; println(j); end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "foo\n",
      "bar\n",
      "baz\n"
     ]
    }
   ],
   "source": [
    "for s in [\"foo\",\"bar\",\"baz\"]\n",
    " println(s)\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1,\"apple\")\n",
      "(1,\"banana\")\n",
      "(1,\"pear\")\n",
      "(2,\"apple\")\n",
      "(2,\"banana\")\n",
      "(2,\"pear\")\n"
     ]
    }
   ],
   "source": [
    "# OH! This is AWESOME!\n",
    "for i = 1:2, j in [\"apple\", \"banana\", \"pear\"]\n",
    " println((i, j))\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "positive_exp (generic function with 1 method)"
      ]
     },
     "execution_count": 120,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "positive_exp(x) = x>=0 ? exp(-x) : throw(DomainError())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.36787944117144233"
      ]
     },
     "execution_count": 121,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "positive_exp(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "LoadError",
     "evalue": "LoadError: DomainError:\nwhile loading In[122], in expression starting on line 1",
     "output_type": "error",
     "traceback": [
      "LoadError: DomainError:\nwhile loading In[122], in expression starting on line 1",
      "",
      " in positive_exp at In[120]:1"
     ]
    }
   ],
   "source": [
    "positive_exp(-100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 123,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "typeof(DomainError()) <: Exception"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "LoadError",
     "evalue": "LoadError: UndefVarError: a_missing_variable not defined\nwhile loading In[125], in expression starting on line 1",
     "output_type": "error",
     "traceback": [
      "LoadError: UndefVarError: a_missing_variable not defined\nwhile loading In[125], in expression starting on line 1",
      ""
     ]
    }
   ],
   "source": [
    "throw(UndefVarError(:a_missing_variable))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "fussy_sqrt (generic function with 1 method)"
      ]
     },
     "execution_count": 126,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fussy_sqrt(x) = x >= 0 ? sqrt(x) : error(\"negative x not allowed\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10.0"
      ]
     },
     "execution_count": 127,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fussy_sqrt(100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 128,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "LoadError",
     "evalue": "LoadError: negative x not allowed\nwhile loading In[128], in expression starting on line 1",
     "output_type": "error",
     "traceback": [
      "LoadError: negative x not allowed\nwhile loading In[128], in expression starting on line 1",
      "",
      " in fussy_sqrt at In[126]:1"
     ]
    }
   ],
   "source": [
    "fussy_sqrt(-250)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "verbose_fussy_sqrt (generic function with 1 method)"
      ]
     },
     "execution_count": 129,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "function verbose_fussy_sqrt(x)\n",
    " println(\"before fussy_sqrt\")\n",
    " r = fussy_sqrt(x)\n",
    " println(\"after fussy_sqrt\")\n",
    " return r\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "before fussy_sqrt\n"
     ]
    },
    {
     "ename": "LoadError",
     "evalue": "LoadError: negative x not allowed\nwhile loading In[130], in expression starting on line 1",
     "output_type": "error",
     "traceback": [
      "LoadError: negative x not allowed\nwhile loading In[130], in expression starting on line 1",
      "",
      " in verbose_fussy_sqrt at In[129]:3"
     ]
    }
   ],
   "source": [
    "verbose_fussy_sqrt(-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO: Hi\n",
      "WARNING: Hi\n"
     ]
    },
    {
     "ename": "LoadError",
     "evalue": "LoadError: Hi\nwhile loading In[131], in expression starting on line 3",
     "output_type": "error",
     "traceback": [
      "LoadError: Hi\nwhile loading In[131], in expression starting on line 3",
      ""
     ]
    }
   ],
   "source": [
    "info(\"Hi\"); 1+1\n",
    "warn(\"Hi\"); 1+1\n",
    "error(\"Hi\"); 1+1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    " try error() end #Returns nothing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 133,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "step 1 ok\n",
      "ErrorException(\"step 2 failed\")\n",
      "step 4 is ensured\n"
     ]
    }
   ],
   "source": [
    "try\n",
    "    println(\"step 1 ok\")\n",
    "    error(\"step 2 failed\")\n",
    "    println(\"step 3 was never reached\")\n",
    "catch e\n",
    "    if isa(e, DomainError)\n",
    "        # Obviously, it's not\n",
    "    else\n",
    "        println(e)\n",
    "    end\n",
    "finally\n",
    "    println(\"step 4 is ensured\")\n",
    "end\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting jupyter-themer\n",
      "  Downloading jupyter-themer-0.1.2.tar.gz\n",
      "Requirement already satisfied (use --upgrade to upgrade): jupyter in /Users/utensil/miniconda2/lib/python2.7/site-packages (from jupyter-themer)\n",
      "Requirement already satisfied (use --upgrade to upgrade): notebook in /Users/utensil/miniconda2/lib/python2.7/site-packages (from jupyter-themer)\n",
      "Building wheels for collected packages: jupyter-themer\n",
      "  Running setup.py bdist_wheel for jupyter-themer: started\n",
      "  Running setup.py bdist_wheel for jupyter-themer: finished with status 'done'\n",
      "  Stored in directory: /Users/utensil/Library/Caches/pip/wheels/de/60/66/02ff107061ba3f1122bc30954652709197d6cd66c0ccdcdfb0\n",
      "Successfully built jupyter-themer\n",
      "Installing collected packages: jupyter-themer\n",
      "Successfully installed jupyter-themer-0.1.2\n"
     ]
    }
   ],
   "source": [
    "# https://github.com/transcranial/jupyter-themer\n",
    "run(`pip install jupyter-themer`)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Custom jupyter notebook theme created - refresh any open jupyter notebooks to apply theme.\n"
     ]
    }
   ],
   "source": [
    "run(`jupyter-themer -c tomorrow-night-eighties`)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Jupyter notebook reverted to default style.\n"
     ]
    }
   ],
   "source": [
    "run(`jupyter-themer`)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 150,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "producer (generic function with 1 method)"
      ]
     },
     "execution_count": 150,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "function producer()\n",
    "    produce(\"start\")\n",
    "    for n=1:4\n",
    "        produce(2n)\n",
    "    end\n",
    "    produce(\"stop\")\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 155,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Task (runnable) @0x000000010d322620"
      ]
     },
     "execution_count": 155,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p = Task(producer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 156,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ASCIIString: start\n",
      "Int64: 2\n",
      "Int64: 4\n",
      "Int64: 6\n",
      "Int64: 8\n",
      "ASCIIString: stop\n",
      "Tuple{}: ()\n"
     ]
    }
   ],
   "source": [
    "for i=0:6\n",
    "    got = consume(p)\n",
    "    println(\"$(typeof(got)): $got\")\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 157,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ASCIIString: start\n",
      "Int64: 2\n",
      "Int64: 4\n",
      "Int64: 6\n",
      "Int64: 8\n",
      "ASCIIString: stop\n"
     ]
    }
   ],
   "source": [
    "for got in Task(producer)\n",
    "    println(\"$(typeof(got)): $got\")\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 158,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       ":done"
      ]
     },
     "execution_count": 158,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p.state"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div class=\"wy-table-responsive\"><table border=\"1\" class=\"docutils\" id=\"man-scope-table\">\n",
    "<colgroup>\n",
    "<col width=\"28%\">\n",
    "<col width=\"27%\">\n",
    "<col width=\"45%\">\n",
    "</colgroup>\n",
    "<thead valign=\"bottom\">\n",
    "<tr class=\"row-odd\"><th class=\"head\">Scope name</th>\n",
    "<th class=\"head\" colspan=\"2\">block/construct introducing this kind of scope</th>\n",
    "</tr>\n",
    "</thead>\n",
    "<tbody valign=\"top\">\n",
    "<tr class=\"row-even\"><td><a class=\"reference internal\" href=\"#man-global\"><span>global</span></a></td>\n",
    "<td colspan=\"2\"><div class=\"first last line-block\">\n",
    "<div class=\"line\">module, baremodule, at interactive prompt (REPL)</div>\n",
    "</div>\n",
    "</td>\n",
    "</tr>\n",
    "<tr class=\"row-odd\"><td rowspan=\"2\"><a class=\"reference internal\" href=\"#man-local-scope\"><span>local</span></a></td>\n",
    "<td><a class=\"reference internal\" href=\"#man-soft-scope\"><span>soft</span></a></td>\n",
    "<td><div class=\"first last line-block\">\n",
    "<div class=\"line\">for, while, list-comprehensions,\n",
    "try-catch-finally, let</div>\n",
    "</div>\n",
    "</td>\n",
    "</tr>\n",
    "<tr class=\"row-even\"><td><a class=\"reference internal\" href=\"#man-hard-scope\"><span>hard</span></a></td>\n",
    "<td><div class=\"first last line-block\">\n",
    "<div class=\"line\">functions (either syntax, anonymous &amp; do-blocks)</div>\n",
    "<div class=\"line\">type, immutable, macro</div>\n",
    "</div>\n",
    "</td>\n",
    "</tr>\n",
    "</tbody>\n",
    "</table></div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 162,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "local_let\n",
      "local_let_2\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "\"global\""
      ]
     },
     "execution_count": 162,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "let\n",
    "    global x = \"global\"\n",
    "    # a new scope\n",
    "    let\n",
    "        local x = \"local_let\"\n",
    "        # not a new scope\n",
    "        begin\n",
    "            # not a new scope\n",
    "            if x == \"local_let\"\n",
    "                println(x)\n",
    "            end\n",
    "        end\n",
    "        let\n",
    "            local x = \"local_let_2\"\n",
    "            println(x)\n",
    "        end\n",
    "    end\n",
    "end\n",
    "x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`for` loops and comprehensions have the following behavior: any new variables introduced in their body scopes are freshly allocated for each loop iteration. This is in contrast to `while` loops which reuse the variables for all iterations. Therefore these constructs are similar to `while` loops with `let` blocks inside"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 163,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 163,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "i = 0\n",
    "for i = 1:3\n",
    "end\n",
    "i  # here equal to 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 164,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 164,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = 0\n",
    "[ x for x=1:3 ]\n",
    "x  # here still equal to 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false,
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(0,3)\n",
      "(0,2)\n",
      "(0,1)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(0,0)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "i = 0\n",
    "j = 3\n",
    "while j > i\n",
    "    println((i, j))\n",
    "    j -= 1\n",
    "end\n",
    "(i, j)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "e = 2.7182818284590..."
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "e"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8.539734222673566"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "const K = e * π"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(1+2)::Int"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "foo (generic function with 1 method)"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "function foo()\n",
    " x::Int8 = 100\n",
    " x\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Int8"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "typeof(foo())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "local y::Int8 = 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y = 200"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Int64"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "typeof(y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "LoadError",
     "evalue": "LoadError: InexactError()\nwhile loading In[24], in expression starting on line 1",
     "output_type": "error",
     "traceback": [
      "LoadError: InexactError()\nwhile loading In[24], in expression starting on line 1",
      "",
      " in convert at int.jl:172"
     ]
    }
   ],
   "source": [
    "local y::Int8=200"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```julia\n",
    "abstract Number\n",
    "abstract Real     <: Number\n",
    "abstract AbstractFloat <: Real\n",
    "abstract Integer  <: Real\n",
    "abstract Signed   <: Integer\n",
    "abstract Unsigned <: Integer\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Integer <: Number"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "false"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Integer <: AbstractFloat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "LoadError",
     "evalue": "LoadError: invalid number of bits in type sevenbit\nwhile loading In[27], in expression starting on line 1",
     "output_type": "error",
     "traceback": [
      "LoadError: invalid number of bits in type sevenbit\nwhile loading In[27], in expression starting on line 1",
      ""
     ]
    }
   ],
   "source": [
    "bitstype 7 sevenbit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "bitstype 128 onetwoeightbits"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "bitstype 128 ∰"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "16"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sizeof(∰)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "type footype\n",
    "     bar\n",
    "     baz::Int\n",
    "     qux::Float64\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "footype(\"bar\",8,12.9)"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ft = footype(\"bar\", 8, 12.9)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "footype(\"bar\",8,12.0)"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "footype(\"bar\", 8, 12)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "LoadError",
     "evalue": "LoadError: MethodError: `convert` has no method matching convert(::Type{Float64}, ::ASCIIString)\nThis may have arisen from a call to the constructor Float64(...),\nsince type constructors fall back to convert methods.\nClosest candidates are:\n  call{T}(::Type{T}, ::Any)\n  convert(::Type{Float64}, !Matched::Int8)\n  convert(::Type{Float64}, !Matched::Int16)\n  ...\nwhile loading In[38], in expression starting on line 1",
     "output_type": "error",
     "traceback": [
      "LoadError: MethodError: `convert` has no method matching convert(::Type{Float64}, ::ASCIIString)\nThis may have arisen from a call to the constructor Float64(...),\nsince type constructors fall back to convert methods.\nClosest candidates are:\n  call{T}(::Type{T}, ::Any)\n  convert(::Type{Float64}, !Matched::Int8)\n  convert(::Type{Float64}, !Matched::Int16)\n  ...\nwhile loading In[38], in expression starting on line 1",
      "",
      " in call at In[32]:2"
     ]
    }
   ],
   "source": [
    "footype(\"bar\", 8, \"12.9\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "footype"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "typeof(ft)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3-element Array{Symbol,1}:\n",
       " :bar\n",
       " :baz\n",
       " :qux"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fieldnames(ft)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3-element Array{Symbol,1}:\n",
       " :bar\n",
       " :baz\n",
       " :qux"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fieldnames(footype)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1//2"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ft.bar = 1//2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Composite types with no fields are singletons; there can be only one instance of such types:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "type NoFields\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "is(NoFields(), NoFields())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "immutable MyComplex\n",
    "  real::Float64\n",
    "  imag::Float64\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "MyComplex(12.0,34.0)"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = MyComplex(12, 34)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12.0"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c.real"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "LoadError",
     "evalue": "LoadError: type MyComplex is immutable\nwhile loading In[48], in expression starting on line 1",
     "output_type": "error",
     "traceback": [
      "LoadError: type MyComplex is immutable\nwhile loading In[48], in expression starting on line 1",
      ""
     ]
    }
   ],
   "source": [
    "c.real = 13"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Union{AbstractString,Int64}"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "IntOrString = Union{Int,AbstractString}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1 :: IntOrString"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"1\""
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"1\" :: IntOrString"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "LoadError",
     "evalue": "LoadError: TypeError: typeassert: expected Union{AbstractString,Int64}, got Float64\nwhile loading In[52], in expression starting on line 1",
     "output_type": "error",
     "traceback": [
      "LoadError: TypeError: typeassert: expected Union{AbstractString,Int64}, got Float64\nwhile loading In[52], in expression starting on line 1",
      ""
     ]
    }
   ],
   "source": [
    "1.0 :: IntOrString"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "type MyPoint{T}\n",
    "  x::T\n",
    "  y::T\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "MyPoint{Int64}(1,2)"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mp = MyPoint(1, 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "LoadError",
     "evalue": "LoadError: MethodError: `convert` has no method matching convert(::Type{MyPoint{T}}, ::Int64, ::ASCIIString)\nThis may have arisen from a call to the constructor MyPoint{T}(...),\nsince type constructors fall back to convert methods.\nClosest candidates are:\n  MyPoint{T}(::T, !Matched::T)\n  call{T}(::Type{T}, ::Any)\n  convert{T}(::Type{T}, !Matched::T)\nwhile loading In[55], in expression starting on line 1",
     "output_type": "error",
     "traceback": [
      "LoadError: MethodError: `convert` has no method matching convert(::Type{MyPoint{T}}, ::Int64, ::ASCIIString)\nThis may have arisen from a call to the constructor MyPoint{T}(...),\nsince type constructors fall back to convert methods.\nClosest candidates are:\n  MyPoint{T}(::T, !Matched::T)\n  call{T}(::Type{T}, ::Any)\n  convert{T}(::Type{T}, !Matched::T)\nwhile loading In[55], in expression starting on line 1",
      "",
      " in call at essentials.jl:57"
     ]
    }
   ],
   "source": [
    "mp = MyPoint(1, \"2\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "MyPoint{Float64} <: MyPoint"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Float64 <: Real"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "false"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "MyPoint{Float64} <: MyPoint{Real}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "abstract Pointly{T}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Pointly{Int} <: Pointly"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "type SpecificPoint{T} <: Pointly{T}\n",
    "  x::T\n",
    "  y::T\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "SpecificPoint{AbstractString} <: Pointly"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "SpecificPoint{ASCIIString}(\"a\",\"b\")"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "SpecificPoint(\"a\", \"b\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "abstract RealPoint{T<:Real}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "RealPoint{Float32} <: RealPoint"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Tuple{Int,AbstractString} <: Tuple{Real,Any}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "false"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Tuple{Int,AbstractString} <: Tuple{Real,}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1.0,1.0)"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(1.0, 1.0) :: Tuple{Vararg{Real}}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "isa((\"1\",1,2), Tuple{AbstractString,Vararg{Int}})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "false"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "isa((\"1\",1,2,3.0), Tuple{AbstractString,Vararg{Int}})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "isa(Float64, Type{Float64})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "false"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "isa(Float64, Type{Real})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "bitstype 64 MyPtr{T}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "false"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "MyPtr{Float64} <: MyPtr{Real}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "MyPtr{Float64} <: MyPtr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "MyPtr{onetwoeightbits}"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "MyPtr{onetwoeightbits}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "MyPtr{T}"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "typealias MyAliasPtr MyPtr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "MyAliasPtr <: MyPtr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "MyPtr <: MyPtr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Array{Float64,1} <: Array{Float64} <: Array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Array{T,2}"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "typealias MyVector{T} Array{T,1}\n",
    "typealias MyMatrix{T} Array{T,2}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "AbstractFloat"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "super(Float64)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Real"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "super(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Number"
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "super(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Any"
      ]
     },
     "execution_count": 96,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "super(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "First\n"
     ]
    }
   ],
   "source": [
    "function firstlast(b::Bool)\n",
    "    return b ? \"First\" : \"Last\"\n",
    "end\n",
    "\n",
    "println(firstlast(true))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "firstlast (generic function with 3 methods)"
      ]
     },
     "execution_count": 98,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "firstlast(::Type{Val{true}}) = \"First\"\n",
    "firstlast(::Type{Val{false}}) = \"Last\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "No documentation found.\n",
       "\\texttt{firstlast} is a generic \\texttt{Function}.\n",
       "\\begin{verbatim}\n",
       "# 3 methods for generic function \"firstlast\":\n",
       "firstlast(b::Bool) at In[97]:2\n",
       "firstlast(::Type{Val{true}}) at In[98]:1\n",
       "firstlast(::Type{Val{false}}) at In[98]:2\n",
       "\\end{verbatim}\n"
      ],
      "text/markdown": [
       "No documentation found.\n",
       "\n",
       "`firstlast` is a generic `Function`.\n",
       "\n",
       "```julia\n",
       "# 3 methods for generic function \"firstlast\":\n",
       "firstlast(b::Bool) at In[97]:2\n",
       "firstlast(::Type{Val{true}}) at In[98]:1\n",
       "firstlast(::Type{Val{false}}) at In[98]:2\n",
       "```\n"
      ],
      "text/plain": [
       "No documentation found.\n",
       "\n",
       "`firstlast` is a generic `Function`.\n",
       "\n",
       "```julia\n",
       "# 3 methods for generic function \"firstlast\":\n",
       "firstlast(b::Bool) at In[97]:2\n",
       "firstlast(::Type{Val{true}}) at In[98]:1\n",
       "firstlast(::Type{Val{false}}) at In[98]:2\n",
       "```\n"
      ]
     },
     "execution_count": 99,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@doc firstlast"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"First\""
      ]
     },
     "execution_count": 106,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "firstlast(Val{true})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "firstlast (generic function with 4 methods)"
      ]
     },
     "execution_count": 107,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "firstlast(::Type{Val{3}}) = \"3\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"3\""
      ]
     },
     "execution_count": 108,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "firstlast(Val{3})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "LoadError",
     "evalue": "LoadError: MethodError: `firstlast` has no method matching firstlast(::Int64)\nwhile loading In[109], in expression starting on line 1",
     "output_type": "error",
     "traceback": [
      "LoadError: MethodError: `firstlast` has no method matching firstlast(::Int64)\nwhile loading In[109], in expression starting on line 1",
      ""
     ]
    }
   ],
   "source": [
    "firstlast(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "LoadError",
     "evalue": "LoadError: MethodError: `isnull` has no method matching isnull(::Int64)\nwhile loading In[110], in expression starting on line 1",
     "output_type": "error",
     "traceback": [
      "LoadError: MethodError: `isnull` has no method matching isnull(::Int64)\nwhile loading In[110], in expression starting on line 1",
      ""
     ]
    }
   ],
   "source": [
    "isnull(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "false"
      ]
     },
     "execution_count": 111,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "isnull(Nullable(3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "LoadError",
     "evalue": "LoadError: NullException()\nwhile loading In[112], in expression starting on line 1",
     "output_type": "error",
     "traceback": [
      "LoadError: NullException()\nwhile loading In[112], in expression starting on line 1",
      "",
      " in get at nullable.jl:30"
     ]
    }
   ],
   "source": [
    "get(Nullable{Float64}())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "20 methods for generic function <b>display</b>:<ul><li> display() at <a href=\"https://github.com/JuliaLang/IJulia.jl/tree/a675ac5c5b08bf75a2f4d2f3b80035252a4af3c1/src/inline.jl#L53\" target=\"_blank\">/Users/utensil/.julia/v0.4/IJulia/src/inline.jl:53</a><li> display(d::<b>Display</b>, mime::<b>AbstractString</b>, x) at <a href=\"https://github.com/JuliaLang/julia/tree/2ac304dfba75fad148d4070ef4f8a2e400c305bb/base/multimedia.jl#L110\" target=\"_blank\">multimedia.jl:110</a><li> display(mime::<b>AbstractString</b>, x) at <a href=\"https://github.com/JuliaLang/julia/tree/2ac304dfba75fad148d4070ef4f8a2e400c305bb/base/multimedia.jl#L111\" target=\"_blank\">multimedia.jl:111</a><li> display(d::<b>TextDisplay</b>, M::<b>MIME{symbol(\"text/plain\")}</b>, x) at <a href=\"https://github.com/JuliaLang/julia/tree/2ac304dfba75fad148d4070ef4f8a2e400c305bb/base/multimedia.jl#L119\" target=\"_blank\">multimedia.jl:119</a><li> display(d::<b>TextDisplay</b>, x) at <a href=\"https://github.com/JuliaLang/julia/tree/2ac304dfba75fad148d4070ef4f8a2e400c305bb/base/multimedia.jl#L120\" target=\"_blank\">multimedia.jl:120</a><li> display(m::<b>MIME{mime}</b>, x) at <a href=\"https://github.com/JuliaLang/julia/tree/2ac304dfba75fad148d4070ef4f8a2e400c305bb/base/multimedia.jl#L170\" target=\"_blank\">multimedia.jl:170</a><li> display(d::<b>Base.REPL.REPLDisplay{R<:Base.REPL.AbstractREPL}</b>, ::<b>MIME{symbol(\"text/plain\")}</b>, x) at <a href=\"https://github.com/JuliaLang/julia/tree/2ac304dfba75fad148d4070ef4f8a2e400c305bb/base/REPL.jl#L112\" target=\"_blank\">REPL.jl:112</a><li> display(d::<b>Base.REPL.REPLDisplay{R<:Base.REPL.AbstractREPL}</b>, md::<b>Base.Markdown.MD</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2ac304dfba75fad148d4070ef4f8a2e400c305bb/base/markdown/render/terminal/render.jl#L126\" target=\"_blank\">markdown/render/terminal/render.jl:126</a><li> display(d::<b>Base.REPL.REPLDisplay{R<:Base.REPL.AbstractREPL}</b>, md::<b>Array{Base.Markdown.MD,1}</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/2ac304dfba75fad148d4070ef4f8a2e400c305bb/base/markdown/Markdown.jl#L61\" target=\"_blank\">markdown/Markdown.jl:61</a><li> display(d::<b>Base.REPL.REPLDisplay{R<:Base.REPL.AbstractREPL}</b>, x) at <a href=\"https://github.com/JuliaLang/julia/tree/2ac304dfba75fad148d4070ef4f8a2e400c305bb/base/REPL.jl#L117\" target=\"_blank\">REPL.jl:117</a><li> display(d::<b>IPythonDisplay.InlineDisplay</b>, ::<b>MIME{symbol(\"text/html\")}</b>, x) at <a href=\"https://github.com/JuliaLang/IJulia.jl/tree/a675ac5c5b08bf75a2f4d2f3b80035252a4af3c1/src/inline.jl#L19\" target=\"_blank\">/Users/utensil/.julia/v0.4/IJulia/src/inline.jl:19</a><li> display(d::<b>IPythonDisplay.InlineDisplay</b>, ::<b>MIME{symbol(\"text/latex\")}</b>, x) at <a href=\"https://github.com/JuliaLang/IJulia.jl/tree/a675ac5c5b08bf75a2f4d2f3b80035252a4af3c1/src/inline.jl#L19\" target=\"_blank\">/Users/utensil/.julia/v0.4/IJulia/src/inline.jl:19</a><li> display(d::<b>IPythonDisplay.InlineDisplay</b>, ::<b>MIME{symbol(\"image/svg+xml\")}</b>, x) at <a href=\"https://github.com/JuliaLang/IJulia.jl/tree/a675ac5c5b08bf75a2f4d2f3b80035252a4af3c1/src/inline.jl#L19\" target=\"_blank\">/Users/utensil/.julia/v0.4/IJulia/src/inline.jl:19</a><li> display(d::<b>IPythonDisplay.InlineDisplay</b>, ::<b>MIME{symbol(\"image/png\")}</b>, x) at <a href=\"https://github.com/JuliaLang/IJulia.jl/tree/a675ac5c5b08bf75a2f4d2f3b80035252a4af3c1/src/inline.jl#L19\" target=\"_blank\">/Users/utensil/.julia/v0.4/IJulia/src/inline.jl:19</a><li> display(d::<b>IPythonDisplay.InlineDisplay</b>, ::<b>MIME{symbol(\"image/jpeg\")}</b>, x) at <a href=\"https://github.com/JuliaLang/IJulia.jl/tree/a675ac5c5b08bf75a2f4d2f3b80035252a4af3c1/src/inline.jl#L19\" target=\"_blank\">/Users/utensil/.julia/v0.4/IJulia/src/inline.jl:19</a><li> display(d::<b>IPythonDisplay.InlineDisplay</b>, ::<b>MIME{symbol(\"text/plain\")}</b>, x) at <a href=\"https://github.com/JuliaLang/IJulia.jl/tree/a675ac5c5b08bf75a2f4d2f3b80035252a4af3c1/src/inline.jl#L19\" target=\"_blank\">/Users/utensil/.julia/v0.4/IJulia/src/inline.jl:19</a><li> display(d::<b>IPythonDisplay.InlineDisplay</b>, ::<b>MIME{symbol(\"text/markdown\")}</b>, x) at <a href=\"https://github.com/JuliaLang/IJulia.jl/tree/a675ac5c5b08bf75a2f4d2f3b80035252a4af3c1/src/inline.jl#L19\" target=\"_blank\">/Users/utensil/.julia/v0.4/IJulia/src/inline.jl:19</a><li> display(d::<b>IPythonDisplay.InlineDisplay</b>, m::<b>MIME{symbol(\"application/x-latex\")}</b>, x) at <a href=\"https://github.com/JuliaLang/IJulia.jl/tree/a675ac5c5b08bf75a2f4d2f3b80035252a4af3c1/src/inline.jl#L29\" target=\"_blank\">/Users/utensil/.julia/v0.4/IJulia/src/inline.jl:29</a><li> display(d::<b>IPythonDisplay.InlineDisplay</b>, x) at <a href=\"https://github.com/JuliaLang/IJulia.jl/tree/a675ac5c5b08bf75a2f4d2f3b80035252a4af3c1/src/inline.jl#L34\" target=\"_blank\">/Users/utensil/.julia/v0.4/IJulia/src/inline.jl:34</a><li> display(x) at <a href=\"https://github.com/JuliaLang/julia/tree/2ac304dfba75fad148d4070ef4f8a2e400c305bb/base/multimedia.jl#L162\" target=\"_blank\">multimedia.jl:162</a></ul>"
      ],
      "text/plain": [
       "# 20 methods for generic function \"display\":\n",
       "display() at /Users/utensil/.julia/v0.4/IJulia/src/inline.jl:53\n",
       "display(d::Display, mime::AbstractString, x) at multimedia.jl:110\n",
       "display(mime::AbstractString, x) at multimedia.jl:111\n",
       "display(d::TextDisplay, M::MIME{symbol(\"text/plain\")}, x) at multimedia.jl:119\n",
       "display(d::TextDisplay, x) at multimedia.jl:120\n",
       "display(m::MIME{mime}, x) at multimedia.jl:170\n",
       "display(d::Base.REPL.REPLDisplay{R<:Base.REPL.AbstractREPL}, ::MIME{symbol(\"text/plain\")}, x) at REPL.jl:112\n",
       "display(d::Base.REPL.REPLDisplay{R<:Base.REPL.AbstractREPL}, md::Base.Markdown.MD) at markdown/render/terminal/render.jl:126\n",
       "display(d::Base.REPL.REPLDisplay{R<:Base.REPL.AbstractREPL}, md::Array{Base.Markdown.MD,1}) at markdown/Markdown.jl:61\n",
       "display(d::Base.REPL.REPLDisplay{R<:Base.REPL.AbstractREPL}, x) at REPL.jl:117\n",
       "display(d::IPythonDisplay.InlineDisplay, ::MIME{symbol(\"text/html\")}, x) at /Users/utensil/.julia/v0.4/IJulia/src/inline.jl:19\n",
       "display(d::IPythonDisplay.InlineDisplay, ::MIME{symbol(\"text/latex\")}, x) at /Users/utensil/.julia/v0.4/IJulia/src/inline.jl:19\n",
       "display(d::IPythonDisplay.InlineDisplay, ::MIME{symbol(\"image/svg+xml\")}, x) at /Users/utensil/.julia/v0.4/IJulia/src/inline.jl:19\n",
       "display(d::IPythonDisplay.InlineDisplay, ::MIME{symbol(\"image/png\")}, x) at /Users/utensil/.julia/v0.4/IJulia/src/inline.jl:19\n",
       "display(d::IPythonDisplay.InlineDisplay, ::MIME{symbol(\"image/jpeg\")}, x) at /Users/utensil/.julia/v0.4/IJulia/src/inline.jl:19\n",
       "display(d::IPythonDisplay.InlineDisplay, ::MIME{symbol(\"text/plain\")}, x) at /Users/utensil/.julia/v0.4/IJulia/src/inline.jl:19\n",
       "display(d::IPythonDisplay.InlineDisplay, ::MIME{symbol(\"text/markdown\")}, x) at /Users/utensil/.julia/v0.4/IJulia/src/inline.jl:19\n",
       "display(d::IPythonDisplay.InlineDisplay, m::MIME{symbol(\"application/x-latex\")}, x) at /Users/utensil/.julia/v0.4/IJulia/src/inline.jl:29\n",
       "display(d::IPythonDisplay.InlineDisplay, x) at /Users/utensil/.julia/v0.4/IJulia/src/inline.jl:34\n",
       "display(x) at multimedia.jl:162"
      ]
     },
     "execution_count": 113,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "methods(display)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "optional_function (generic function with 3 methods)"
      ]
     },
     "execution_count": 115,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "optional_function(a=1, b=2) = a + b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "3 methods for generic function <b>optional_function</b>:<ul><li> optional_function() at In[115]:1<li> optional_function(a) at In[115]:1<li> optional_function(a, b) at In[115]:1</ul>"
      ],
      "text/plain": [
       "# 3 methods for generic function \"optional_function\":\n",
       "optional_function() at In[115]:1\n",
       "optional_function(a) at In[115]:1\n",
       "optional_function(a, b) at In[115]:1"
      ]
     },
     "execution_count": 116,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "methods(optional_function)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "abc￹abc￻abc\n"
     ]
    }
   ],
   "source": [
    "println(\"abc\\ufff9abc\\ufffbabc\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "abc￺abc￻abc\n"
     ]
    }
   ],
   "source": [
    "println(\"abc\\ufffaabc\\ufffbabc\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "‮ABCDE‭XYZ\n"
     ]
    }
   ],
   "source": [
    "println(\"\\u202eABCDE\\u202dXYZ\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "大字‍小字\n"
     ]
    }
   ],
   "source": [
    "println(\"大字\\u200d小字\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "call (generic function with 1094 methods)"
      ]
     },
     "execution_count": 125,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Base.call(x::Number, arg) = x * arg"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10"
      ]
     },
     "execution_count": 126,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_number=10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 127,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "10(20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 128,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "emptyfunc (generic function with 0 methods)"
      ]
     },
     "execution_count": 128,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "function emptyfunc\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "type OrderedPair\n",
    "  x::Real\n",
    "  y::Real\n",
    "\n",
    "  OrderedPair(x,y) = x > y ? error(\"out of order\") : new(x,y)\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "OrderedPair(1,2)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "OrderedPair(1, 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "LoadError",
     "evalue": "LoadError: out of order\nwhile loading In[3], in expression starting on line 1",
     "output_type": "error",
     "traceback": [
      "LoadError: out of order\nwhile loading In[3], in expression starting on line 1",
      "",
      " in call at In[1]:5"
     ]
    }
   ],
   "source": [
    "OrderedPair(2, 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "type Foo\n",
    "  bar\n",
    "  baz\n",
    "\n",
    "  Foo(bar,baz) = new(bar,baz)\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "type SelfReferential\n",
    "  obj::SelfReferential\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "type BetterSelfReferential\n",
    "  obj::BetterSelfReferential\n",
    "\n",
    "  BetterSelfReferential() = (x = new(); x.obj = x)\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "LoadError",
     "evalue": "LoadError: MethodError: `convert` has no method matching convert(::Type{SelfReferential})\nThis may have arisen from a call to the constructor SelfReferential(...),\nsince type constructors fall back to convert methods.\nClosest candidates are:\n  convert{T}(::Type{T}, !Matched::T)\n  SelfReferential(, !Matched::SelfReferential)\n  SelfReferential(, !Matched::Any)\n  ...\nwhile loading In[4], in expression starting on line 1",
     "output_type": "error",
     "traceback": [
      "LoadError: MethodError: `convert` has no method matching convert(::Type{SelfReferential})\nThis may have arisen from a call to the constructor SelfReferential(...),\nsince type constructors fall back to convert methods.\nClosest candidates are:\n  convert{T}(::Type{T}, !Matched::T)\n  SelfReferential(, !Matched::SelfReferential)\n  SelfReferential(, !Matched::Any)\n  ...\nwhile loading In[4], in expression starting on line 1",
      "",
      " in call at essentials.jl:57"
     ]
    }
   ],
   "source": [
    "sr = SelfReferential()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "BetterSelfReferential(BetterSelfReferential(#= circular reference =#))"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bsr = BetterSelfReferential()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "is(bsr, bsr.obj.obj)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In some cases you could consider adding methods to Base.convert instead of defining a constructor, because defining a convert() method automatically defines a corresponding constructor, while the reverse is not true. That is, defining Base.convert(::Type{T}, args...) = ... automatically defines a constructor T(args...) = ....\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "type SummedArray{T<:Number,S<:Number}\n",
    "    data::Vector{T}\n",
    "    sum::S\n",
    "\n",
    "    function call{T}(::Type{SummedArray}, a::Vector{T})\n",
    "        S = widen(T)\n",
    "        new{T,S}(a, sum(S, a))\n",
    "    end\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "SummedArray{Int32,Int64}(Int32[1,2,3],6)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sa = SummedArray(Vector{Int32}([1, 2, 3]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sa.sum"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```\n",
    "promote_rule(::Type{UInt8}, ::Type{Int8}) = Int\n",
    "promote_rule(::Type{BigInt}, ::Type{Int8}) = BigInt\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Int64"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "promote_type(Int8, UInt16)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```julia\n",
    "promote_rule{T<:Integer}(::Type{Rational{T}}, ::Type{T}) = Rational{T}\n",
    "promote_rule{T<:Integer,S<:Integer}(::Type{Rational{T}}, ::Type{S}) = Rational{promote_type(T,S)}\n",
    "promote_rule{T<:Integer,S<:Integer}(::Type{Rational{T}}, ::Type{Rational{S}}) = Rational{promote_type(T,S)}\n",
    "promote_rule{T<:Integer,S<:AbstractFloat}(::Type{Rational{T}}, ::Type{S}) = promote_type(T,S)\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "immutable Squares\n",
    "   count::Int\n",
    "end\n",
    "Base.start(::Squares) = 1\n",
    "Base.next(S::Squares, state) = (state*state, state+1)\n",
    "Base.done(S::Squares, s) = s > S.count;\n",
    "Base.eltype(::Type{Squares}) = Int # Note that this is defined for the type\n",
    "Base.length(S::Squares) = S.count;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "4\n",
      "9\n",
      "16\n",
      "25\n",
      "36\n",
      "49\n"
     ]
    }
   ],
   "source": [
    "for i in Squares(7)\n",
    "   println(i)\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "length(Squares(100)) == 100"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "25 in Squares(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3383.5,3024.355854282583)"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mean(Squares(100)), std(Squares(100))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1x100 Array{Int64,2}:\n",
       " 1  4  9  16  25  36  49  64  81  100  …  9025  9216  9409  9604  9801  10000"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    " collect(Squares(100))'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1955361914"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Base.sum(S::Squares) = (n = S.count; return n*(n+1)*(2n+1)÷6)\n",
    "       sum(Squares(1803))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1 + 2 | 3 == (1 + 2) | 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1 .* 2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```julia\n",
    "module MyModule\n",
    "using Lib\n",
    "\n",
    "using BigLib: thing1, thing2\n",
    "\n",
    "import Base.show\n",
    "\n",
    "importall OtherLib\n",
    "\n",
    "export MyType, foo\n",
    "\n",
    "type MyType\n",
    "    x\n",
    "end\n",
    "\n",
    "bar(x) = 2x\n",
    "foo(a::MyType) = bar(a.x) + 1\n",
    "\n",
    "show(io, a::MyType) = print(io, \"MyType $(a.x)\")\n",
    "end\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```julia\n",
    "module Parent\n",
    "\n",
    "module Utils\n",
    "...\n",
    "end\n",
    "\n",
    "using .Utils\n",
    "\n",
    "...\n",
    "end\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{verbatim}\n",
       "@time\n",
       "\\end{verbatim}\n",
       "A macro to execute an expression, printing the time it took to execute, the number of allocations, and the total number of bytes its execution caused to be allocated, before returning the value of the expression.\n"
      ],
      "text/markdown": [
       "```\n",
       "@time\n",
       "```\n",
       "\n",
       "A macro to execute an expression, printing the time it took to execute, the number of allocations, and the total number of bytes its execution caused to be allocated, before returning the value of the expression.\n"
      ],
      "text/plain": [
       "```\n",
       "@time\n",
       "```\n",
       "\n",
       "A macro to execute an expression, printing the time it took to execute, the number of allocations, and the total number of bytes its execution caused to be allocated, before returning the value of the expression.\n"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "?@time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  4.591638 seconds (10 allocations: 4.470 GB, 4.91% gc time)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "1x300000000 Array{Int64,2}:\n",
       " 1  4  9  16  25  36  49  64  81  100  121  144  169  …  90000000000000000"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@time collect(Squares(300000000))'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "to re-use documentation between different versions of a function:\n",
    "\n",
    "```\n",
    "@doc \"...\" foo!\n",
    "@doc (@doc foo!) foo\n",
    "    ```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(anonymous function)"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "foo = (x) -> 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "@doc \"fooing\" foo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "fooing\n"
      ],
      "text/markdown": [
       "fooing\n"
      ],
      "text/plain": [
       "fooing\n"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@doc foo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\texttt{abc} is just \\_ABC\\_ as we know\n"
      ],
      "text/markdown": [
       "`abc` is just _ABC_ as we know\n"
      ],
      "text/plain": [
       "`abc` is just _ABC_ as we know\n"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"`abc` is just _ABC_ as we know\"\n",
    "abc = \"abc\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\texttt{abc} is just \\_ABC\\_ as we know\n"
      ],
      "text/markdown": [
       "`abc` is just _ABC_ as we know\n"
      ],
      "text/plain": [
       "`abc` is just _ABC_ as we know\n"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@doc abc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "100-element Array{Int64,1}:\n",
       " 2190216240\n",
       " 2153360720\n",
       " 2153360736\n",
       " 2153360752\n",
       " 2153360768\n",
       " 2225828400\n",
       " 2225828432\n",
       " 2225828528\n",
       " 2205896976\n",
       " 2225828592\n",
       " 2222477008\n",
       " 2206633168\n",
       " 2206633232\n",
       "          ⋮\n",
       "          0\n",
       "          0\n",
       "          0\n",
       "          0\n",
       "          0\n",
       "          0\n",
       "          0\n",
       "          0\n",
       "          0\n",
       "          0\n",
       "          0\n",
       "          0"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "intarray = Array(Int64, 100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "100-element Array{Int64,1}:\n",
       " 0\n",
       " 0\n",
       " 0\n",
       " 0\n",
       " 0\n",
       " 0\n",
       " 0\n",
       " 0\n",
       " 0\n",
       " 0\n",
       " 0\n",
       " 0\n",
       " 0\n",
       " ⋮\n",
       " 0\n",
       " 0\n",
       " 0\n",
       " 0\n",
       " 0\n",
       " 0\n",
       " 0\n",
       " 0\n",
       " 0\n",
       " 0\n",
       " 0\n",
       " 0"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "intarray = zeros(Int64, 100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Int64"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "eltype(intarray)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "100"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "length(intarray)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ndims(intarray)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(100,)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "size(intarray)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1,)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "strides(intarray)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{verbatim}\n",
       "strides(A)\n",
       "\\end{verbatim}\n",
       "Returns a tuple of the memory strides in each dimension\n"
      ],
      "text/markdown": [
       "```\n",
       "strides(A)\n",
       "```\n",
       "\n",
       "Returns a tuple of the memory strides in each dimension\n"
      ],
      "text/plain": [
       "```\n",
       "strides(A)\n",
       "```\n",
       "\n",
       "Returns a tuple of the memory strides in each dimension\n"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@doc strides"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3x3 Array{Any,2}:\n",
       " #undef  #undef  #undef\n",
       " #undef  #undef  #undef\n",
       " #undef  #undef  #undef"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "array = cell((3, 3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3x3 Array{Float64,2}:\n",
       " 0.0  0.0  0.0\n",
       " 0.0  0.0  0.0\n",
       " 0.0  0.0  0.0"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m = zeros((3, 3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3,3)"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "size(m)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "size(m, 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1,3)"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "strides(m)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3-element Array{Float64,1}:\n",
       " 0.262588\n",
       " 0.68179 \n",
       " 0.995355"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rand(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3-element Array{Float64,1}:\n",
       "  1.62027\n",
       " -1.53208\n",
       "  2.52513"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "randn(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{verbatim}\n",
       "eye(m, n)\n",
       "\\end{verbatim}\n",
       "\\texttt{m}-by-\\texttt{n} identity matrix\n",
       "\\begin{verbatim}\n",
       "eye(A)\n",
       "\\end{verbatim}\n",
       "Constructs an identity matrix of the same dimensions and type as \\texttt{A}.\n",
       "\\begin{verbatim}\n",
       "eye(n)\n",
       "\\end{verbatim}\n",
       "\\texttt{n}-by-\\texttt{n} identity matrix\n"
      ],
      "text/markdown": [
       "```\n",
       "eye(m, n)\n",
       "```\n",
       "\n",
       "`m`-by-`n` identity matrix\n",
       "\n",
       "```\n",
       "eye(A)\n",
       "```\n",
       "\n",
       "Constructs an identity matrix of the same dimensions and type as `A`.\n",
       "\n",
       "```\n",
       "eye(n)\n",
       "```\n",
       "\n",
       "`n`-by-`n` identity matrix\n"
      ],
      "text/plain": [
       "```\n",
       "eye(m, n)\n",
       "```\n",
       "\n",
       "`m`-by-`n` identity matrix\n",
       "\n",
       "```\n",
       "eye(A)\n",
       "```\n",
       "\n",
       "Constructs an identity matrix of the same dimensions and type as `A`.\n",
       "\n",
       "```\n",
       "eye(n)\n",
       "```\n",
       "\n",
       "`n`-by-`n` identity matrix\n"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@doc eye"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3x2 Array{Float64,2}:\n",
       " 1.0  0.0\n",
       " 0.0  1.0\n",
       " 0.0  0.0"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ey = eye(3, 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3x3 Array{Int64,2}:\n",
       " 3  3  3\n",
       " 3  3  3\n",
       " 3  3  3"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fm = fill(3, (3, 3))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<table border=\"1\" class=\"docutils\">\n",
    "<colgroup>\n",
    "<col width=\"59%\">\n",
    "<col width=\"41%\">\n",
    "</colgroup>\n",
    "<thead valign=\"bottom\">\n",
    "<tr class=\"row-odd\"><th class=\"head\">Expression</th>\n",
    "<th class=\"head\">Calls</th>\n",
    "</tr>\n",
    "</thead>\n",
    "<tbody valign=\"top\">\n",
    "<tr class=\"row-even\"><td><code class=\"docutils literal\"><span class=\"pre\">[A;</span> <span class=\"pre\">B;</span> <span class=\"pre\">C;</span> <span class=\"pre\">...]</span></code></td>\n",
    "<td><a class=\"reference internal\" href=\"../../stdlib/arrays/#Base.vcat\" title=\"Base.vcat\"><code class=\"xref jl jl-func docutils literal\"><span class=\"pre\">vcat()</span></code></a></td>\n",
    "</tr>\n",
    "<tr class=\"row-odd\"><td><code class=\"docutils literal\"><span class=\"pre\">[A</span> <span class=\"pre\">B</span> <span class=\"pre\">C</span> <span class=\"pre\">...]</span></code></td>\n",
    "<td><a class=\"reference internal\" href=\"../../stdlib/arrays/#Base.hcat\" title=\"Base.hcat\"><code class=\"xref jl jl-func docutils literal\"><span class=\"pre\">hcat()</span></code></a></td>\n",
    "</tr>\n",
    "<tr class=\"row-even\"><td><code class=\"docutils literal\"><span class=\"pre\">[A</span> <span class=\"pre\">B;</span> <span class=\"pre\">C</span> <span class=\"pre\">D;</span> <span class=\"pre\">...]</span></code></td>\n",
    "<td><a class=\"reference internal\" href=\"../../stdlib/arrays/#Base.hvcat\" title=\"Base.hvcat\"><code class=\"xref jl jl-func docutils literal\"><span class=\"pre\">hvcat()</span></code></a></td>\n",
    "</tr>\n",
    "</tbody>\n",
    "</table>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2x3 Array{Int64,2}:\n",
       " 1  2  3\n",
       " 4  5  6"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a, b, c, d, e, f = 1, 2, 3, 4, 5, 6\n",
    " [a b c; d e f]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2x3 Array{Int64,2}:\n",
       " 1  2  3\n",
       " 4  5  6"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hvcat((3,3), a,b,c,d,e,f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3x2 Array{Int64,2}:\n",
       " 1  2\n",
       " 3  4\n",
       " 5  6"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[a b;c d; e f]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3x2 Array{Int64,2}:\n",
       " 1  2\n",
       " 3  4\n",
       " 5  6"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hvcat((2,2,2), a,b,c,d,e,f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{verbatim}\n",
       "hvcat(rows::Tuple{Vararg{Int}}, values...)\n",
       "\\end{verbatim}\n",
       "Horizontal and vertical concatenation in one call. This function is called for block matrix syntax. The first argument specifies the number of arguments to concatenate in each block row.\n",
       "\\begin{verbatim}\n",
       "julia> a, b, c, d, e, f = 1, 2, 3, 4, 5, 6\n",
       "(1,2,3,4,5,6)\n",
       "\n",
       "julia> [a b c; d e f]\n",
       "2x3 Array{Int64,2}:\n",
       " 1  2  3\n",
       " 4  5  6\n",
       "\n",
       "julia> hvcat((3,3), a,b,c,d,e,f)\n",
       "2x3 Array{Int64,2}:\n",
       " 1  2  3\n",
       " 4  5  6\n",
       "\n",
       "julia> [a b;c d; e f]\n",
       "3x2 Array{Int64,2}:\n",
       " 1  2\n",
       " 3  4\n",
       " 5  6\n",
       "\n",
       "julia> hvcat((2,2,2), a,b,c,d,e,f)\n",
       "3x2 Array{Int64,2}:\n",
       " 1  2\n",
       " 3  4\n",
       " 5  6\n",
       "\\end{verbatim}\n",
       "If the first argument is a single integer \\texttt{n}, then all block rows are assumed to have \\texttt{n} block columns.\n"
      ],
      "text/markdown": [
       "```\n",
       "hvcat(rows::Tuple{Vararg{Int}}, values...)\n",
       "```\n",
       "\n",
       "Horizontal and vertical concatenation in one call. This function is called for block matrix syntax. The first argument specifies the number of arguments to concatenate in each block row.\n",
       "\n",
       "```jldoctest\n",
       "julia> a, b, c, d, e, f = 1, 2, 3, 4, 5, 6\n",
       "(1,2,3,4,5,6)\n",
       "\n",
       "julia> [a b c; d e f]\n",
       "2x3 Array{Int64,2}:\n",
       " 1  2  3\n",
       " 4  5  6\n",
       "\n",
       "julia> hvcat((3,3), a,b,c,d,e,f)\n",
       "2x3 Array{Int64,2}:\n",
       " 1  2  3\n",
       " 4  5  6\n",
       "\n",
       "julia> [a b;c d; e f]\n",
       "3x2 Array{Int64,2}:\n",
       " 1  2\n",
       " 3  4\n",
       " 5  6\n",
       "\n",
       "julia> hvcat((2,2,2), a,b,c,d,e,f)\n",
       "3x2 Array{Int64,2}:\n",
       " 1  2\n",
       " 3  4\n",
       " 5  6\n",
       "```\n",
       "\n",
       "If the first argument is a single integer `n`, then all block rows are assumed to have `n` block columns.\n"
      ],
      "text/plain": [
       "```\n",
       "hvcat(rows::Tuple{Vararg{Int}}, values...)\n",
       "```\n",
       "\n",
       "Horizontal and vertical concatenation in one call. This function is called for block matrix syntax. The first argument specifies the number of arguments to concatenate in each block row.\n",
       "\n",
       "```jldoctest\n",
       "julia> a, b, c, d, e, f = 1, 2, 3, 4, 5, 6\n",
       "(1,2,3,4,5,6)\n",
       "\n",
       "julia> [a b c; d e f]\n",
       "2x3 Array{Int64,2}:\n",
       " 1  2  3\n",
       " 4  5  6\n",
       "\n",
       "julia> hvcat((3,3), a,b,c,d,e,f)\n",
       "2x3 Array{Int64,2}:\n",
       " 1  2  3\n",
       " 4  5  6\n",
       "\n",
       "julia> [a b;c d; e f]\n",
       "3x2 Array{Int64,2}:\n",
       " 1  2\n",
       " 3  4\n",
       " 5  6\n",
       "\n",
       "julia> hvcat((2,2,2), a,b,c,d,e,f)\n",
       "3x2 Array{Int64,2}:\n",
       " 1  2\n",
       " 3  4\n",
       " 5  6\n",
       "```\n",
       "\n",
       "If the first argument is a single integer `n`, then all block rows are assumed to have `n` block columns.\n"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@doc hvcat"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div class=\"section\" id=\"indexing\">\n",
    "<span id=\"man-array-indexing\"></span><h3>Indexing<a class=\"headerlink\" href=\"#indexing\" title=\"Permalink to this headline\">¶</a></h3>\n",
    "<p>The general syntax for indexing into an n-dimensional array A is:</p>\n",
    "<div class=\"highlight-julia\"><div class=\"highlight\"><pre><span></span><span class=\"n\">X</span> <span class=\"o\">=</span> <span class=\"n\">A</span><span class=\"p\">[</span><span class=\"n\">I_1</span><span class=\"p\">,</span> <span class=\"n\">I_2</span><span class=\"p\">,</span> <span class=\"o\">...</span><span class=\"p\">,</span> <span class=\"n\">I_n</span><span class=\"p\">]</span>\n",
    "</pre></div>\n",
    "</div>\n",
    "<p>where each <code class=\"docutils literal\"><span class=\"pre\">I_k</span></code> may be:</p>\n",
    "<ol class=\"arabic simple\">\n",
    "<li>A scalar integer</li>\n",
    "<li>A <code class=\"docutils literal\"><span class=\"pre\">Range</span></code> of the form <code class=\"docutils literal\"><span class=\"pre\">a:b</span></code>, or <code class=\"docutils literal\"><span class=\"pre\">a:b:c</span></code></li>\n",
    "<li>A <code class=\"docutils literal\"><span class=\"pre\">:</span></code> or <code class=\"docutils literal\"><span class=\"pre\">Colon()</span></code> to select entire dimensions</li>\n",
    "<li>An arbitrary integer vector, including the empty vector <code class=\"docutils literal\"><span class=\"pre\">[]</span></code></li>\n",
    "<li>A boolean vector</li>\n",
    "</ol>\n",
    "<p>The result <code class=\"docutils literal\"><span class=\"pre\">X</span></code> generally has dimensions\n",
    "<code class=\"docutils literal\"><span class=\"pre\">(length(I_1),</span> <span class=\"pre\">length(I_2),</span> <span class=\"pre\">...,</span> <span class=\"pre\">length(I_n))</span></code>, with location\n",
    "<code class=\"docutils literal\"><span class=\"pre\">(i_1,</span> <span class=\"pre\">i_2,</span> <span class=\"pre\">...,</span> <span class=\"pre\">i_n)</span></code> of <code class=\"docutils literal\"><span class=\"pre\">X</span></code> containing the value\n",
    "<code class=\"docutils literal\"><span class=\"pre\">A[I_1[i_1],</span> <span class=\"pre\">I_2[i_2],</span> <span class=\"pre\">...,</span> <span class=\"pre\">I_n[i_n]]</span></code>. Trailing dimensions\n",
    "indexed with scalars are dropped. For example, the dimensions of <code class=\"docutils literal\"><span class=\"pre\">A[I,</span> <span class=\"pre\">1]</span></code> will be\n",
    "<code class=\"docutils literal\"><span class=\"pre\">(length(I),)</span></code>. Boolean vectors are first transformed with <code class=\"docutils literal\"><span class=\"pre\">find</span></code>; the size of\n",
    "a dimension indexed by a boolean vector will be the number of true values in the vector.\n",
    "As a special part of this syntax, the <code class=\"docutils literal\"><span class=\"pre\">end</span></code> keyword may be used to represent the last\n",
    "index of each dimension within the indexing brackets, as determined by the size of the\n",
    "innermost array being indexed.</p>\n",
    "<p>Alternatively, single elements of a multidimensional array can be indexed as</p>\n",
    "<div class=\"highlight-julia\"><div class=\"highlight\"><pre><span></span><span class=\"n\">x</span> <span class=\"o\">=</span> <span class=\"n\">A</span><span class=\"p\">[</span><span class=\"n\">I</span><span class=\"p\">]</span>\n",
    "</pre></div>\n",
    "</div>\n",
    "<p>where <code class=\"docutils literal\"><span class=\"pre\">I</span></code> is a <code class=\"docutils literal\"><span class=\"pre\">CartesianIndex</span></code>, effectively an <code class=\"docutils literal\"><span class=\"pre\">n</span></code>-tuple of integers.\n",
    "See <a class=\"reference internal\" href=\"#man-array-iteration\"><span>Iteration</span></a> below.</p>\n",
    "<p>Indexing syntax is equivalent to a call to <code class=\"docutils literal\"><span class=\"pre\">getindex</span></code>:</p>\n",
    "<div class=\"highlight-julia\"><div class=\"highlight\"><pre><span></span><span class=\"n\">X</span> <span class=\"o\">=</span> <span class=\"n\">getindex</span><span class=\"p\">(</span><span class=\"n\">A</span><span class=\"p\">,</span> <span class=\"n\">I_1</span><span class=\"p\">,</span> <span class=\"n\">I_2</span><span class=\"p\">,</span> <span class=\"o\">...</span><span class=\"p\">,</span> <span class=\"n\">I_n</span><span class=\"p\">)</span>\n",
    "</pre></div>\n",
    "</div>\n",
    "<p>Example:</p>\n",
    "<div class=\"highlight-julia\"><div class=\"highlight\"><pre><span></span><span class=\"n\">julia</span><span class=\"o\">&gt;</span> <span class=\"n\">x</span> <span class=\"o\">=</span> <span class=\"n\">reshape</span><span class=\"p\">(</span><span class=\"mi\">1</span><span class=\"p\">:</span><span class=\"mi\">16</span><span class=\"p\">,</span> <span class=\"mi\">4</span><span class=\"p\">,</span> <span class=\"mi\">4</span><span class=\"p\">)</span>\n",
    "<span class=\"mi\">4</span><span class=\"n\">x4</span> <span class=\"n\">Array</span><span class=\"p\">{</span><span class=\"kt\">Int64</span><span class=\"p\">,</span><span class=\"mi\">2</span><span class=\"p\">}:</span>\n",
    " <span class=\"mi\">1</span>  <span class=\"mi\">5</span>   <span class=\"mi\">9</span>  <span class=\"mi\">13</span>\n",
    " <span class=\"mi\">2</span>  <span class=\"mi\">6</span>  <span class=\"mi\">10</span>  <span class=\"mi\">14</span>\n",
    " <span class=\"mi\">3</span>  <span class=\"mi\">7</span>  <span class=\"mi\">11</span>  <span class=\"mi\">15</span>\n",
    " <span class=\"mi\">4</span>  <span class=\"mi\">8</span>  <span class=\"mi\">12</span>  <span class=\"mi\">16</span>\n",
    "\n",
    "<span class=\"n\">julia</span><span class=\"o\">&gt;</span> <span class=\"n\">x</span><span class=\"p\">[</span><span class=\"mi\">2</span><span class=\"p\">:</span><span class=\"mi\">3</span><span class=\"p\">,</span> <span class=\"mi\">2</span><span class=\"p\">:</span><span class=\"k\">end</span><span class=\"o\">-</span><span class=\"mi\">1</span><span class=\"p\">]</span>\n",
    "<span class=\"mi\">2</span><span class=\"n\">x2</span> <span class=\"n\">Array</span><span class=\"p\">{</span><span class=\"kt\">Int64</span><span class=\"p\">,</span><span class=\"mi\">2</span><span class=\"p\">}:</span>\n",
    " <span class=\"mi\">6</span>  <span class=\"mi\">10</span>\n",
    " <span class=\"mi\">7</span>  <span class=\"mi\">11</span>\n",
    "</pre></div>\n",
    "</div>\n",
    "<p>Empty ranges of the form <code class=\"docutils literal\"><span class=\"pre\">n:n-1</span></code> are sometimes used to indicate the inter-index\n",
    "location between <code class=\"docutils literal\"><span class=\"pre\">n-1</span></code> and <code class=\"docutils literal\"><span class=\"pre\">n</span></code>.  For example, the <a class=\"reference internal\" href=\"../../stdlib/sort/#Base.searchsorted\" title=\"Base.searchsorted\"><code class=\"xref jl jl-func docutils literal\"><span class=\"pre\">searchsorted()</span></code></a> function uses\n",
    "this convention to indicate the insertion point of a value not found in a sorted\n",
    "array:</p>\n",
    "<div class=\"highlight-julia\"><div class=\"highlight\"><pre><span></span><span class=\"n\">julia</span><span class=\"o\">&gt;</span> <span class=\"n\">a</span> <span class=\"o\">=</span> <span class=\"p\">[</span><span class=\"mi\">1</span><span class=\"p\">,</span><span class=\"mi\">2</span><span class=\"p\">,</span><span class=\"mi\">5</span><span class=\"p\">,</span><span class=\"mi\">6</span><span class=\"p\">,</span><span class=\"mi\">7</span><span class=\"p\">];</span>\n",
    "\n",
    "<span class=\"n\">julia</span><span class=\"o\">&gt;</span> <span class=\"n\">searchsorted</span><span class=\"p\">(</span><span class=\"n\">a</span><span class=\"p\">,</span> <span class=\"mi\">3</span><span class=\"p\">)</span>\n",
    "<span class=\"mi\">3</span><span class=\"p\">:</span><span class=\"mi\">2</span>\n",
    "</pre></div>\n",
    "</div>\n",
    "</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4x4 Array{Int64,2}:\n",
       " 1  5   9  13\n",
       " 2  6  10  14\n",
       " 3  7  11  15\n",
       " 4  8  12  16"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    " x = reshape(1:16, 4, 4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2x2 Array{Int64,2}:\n",
       " 6  10\n",
       " 7  11"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    " x[2:3, 2:end-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3:2"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "3:2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "UnitRange{Int64}"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "typeof(3:2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "UnitRange{Int64}"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "typeof(1:50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(\n",
       "4x3 Array{Float64,2}:\n",
       " 0.897381  0.230063   0.999231 \n",
       " 0.387111  0.0517558  0.188619 \n",
       " 0.80081   0.984446   0.0437768\n",
       " 0.169907  0.683732   0.517761 ,\n",
       "\n",
       "3x2 SubArray{Float64,2,Array{Float64,2},Tuple{UnitRange{Int64},UnitRange{Int64}},1}:\n",
       " 0.230063   0.999231 \n",
       " 0.0517558  0.188619 \n",
       " 0.984446   0.0437768)"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A = rand(4,3)\n",
    "B = sub(A, 1:3, 2:3)\n",
    "(A, B)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "square (generic function with 4 methods)"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "square(x) = x^2\n",
    " @vectorize_1arg Number square"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "4 methods for generic function <b>square</b>:<ul><li> square<i>{T<:Number}</i>(::<b>AbstractArray{T<:Number,1}</b>) at <a href=\"file://U:\\Users\\Administrator\\AppData\\Local\\Julia-0.4.5\\bin\\../share\\julia\\base\\operators.jl\" target=\"_blank\">operators.jl:380</a><li> square<i>{T<:Number}</i>(::<b>AbstractArray{T<:Number,2}</b>) at <a href=\"file://U:\\Users\\Administrator\\AppData\\Local\\Julia-0.4.5\\bin\\../share\\julia\\base\\operators.jl\" target=\"_blank\">operators.jl:381</a><li> square<i>{T<:Number}</i>(::<b>AbstractArray{T<:Number,N}</b>) at <a href=\"file://U:\\Users\\Administrator\\AppData\\Local\\Julia-0.4.5\\bin\\../share\\julia\\base\\operators.jl\" target=\"_blank\">operators.jl:383</a><li> square(x) at In[32]:1</ul>"
      ],
      "text/plain": [
       "# 4 methods for generic function \"square\":\n",
       "square{T<:Number}(::AbstractArray{T<:Number,1}) at operators.jl:380\n",
       "square{T<:Number}(::AbstractArray{T<:Number,2}) at operators.jl:381\n",
       "square{T<:Number}(::AbstractArray{T<:Number,N}) at operators.jl:383\n",
       "square(x) at In[32]:1"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "methods(square)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4x3 Array{Float64,2}:\n",
       " 0.805292   0.052929    0.998462 \n",
       " 0.149855   0.00267866  0.035577 \n",
       " 0.641296   0.969134    0.0019164\n",
       " 0.0288685  0.467489    0.268077 "
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "square(A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(\n",
       "2x1 Array{Float64,2}:\n",
       " 0.243233\n",
       " 0.467999,\n",
       "\n",
       "2x3 Array{Float64,2}:\n",
       " 0.911001  0.851159  0.112441\n",
       " 0.190415  0.946762  0.682602)"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = rand(2,1); A = rand(2,3);\n",
    "(a, A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2x3 Array{Float64,2}:\n",
       " 1.15423   1.09439  0.355674\n",
       " 0.658414  1.41476  1.1506  "
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "broadcast(+, a, A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2x2 Array{Float64,2}:\n",
       " 1.02773  1.03444\n",
       " 1.2525   1.2592 "
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b = rand(1,2)\n",
    "broadcast(+, a, b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3x5 sparse matrix with 0 Float64 entries:"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "spzeros(3,5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3x5 sparse matrix with 3 Float64 entries:\n",
       "\t[1, 1]  =  1.0\n",
       "\t[2, 2]  =  1.0\n",
       "\t[3, 3]  =  1.0"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "speye(3,5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5x18 sparse matrix with 4 Int64 entries:\n",
       "\t[1 ,  4]  =  1\n",
       "\t[4 ,  7]  =  2\n",
       "\t[5 ,  9]  =  3\n",
       "\t[3 , 18]  =  -5"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "I = [1, 4, 3, 5]; J = [4, 7, 18, 9]; V = [1, 2, -5, 3];\n",
    "S = sparse(I,J,V)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "([1,4,5,3],[4,7,9,18])"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "findn(S)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "([1,4,5,3],[4,7,9,18],[1,2,3,-5])"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "findnz(S)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{verbatim}\n",
       "findn(A)\n",
       "\\end{verbatim}\n",
       "Return a vector of indexes for each dimension giving the locations of the non-zeros in \\texttt{A} (determined by \\texttt{A[i]!=0}).\n"
      ],
      "text/markdown": [
       "```\n",
       "findn(A)\n",
       "```\n",
       "\n",
       "Return a vector of indexes for each dimension giving the locations of the non-zeros in `A` (determined by `A[i]!=0`).\n"
      ],
      "text/plain": [
       "```\n",
       "findn(A)\n",
       "```\n",
       "\n",
       "Return a vector of indexes for each dimension giving the locations of the non-zeros in `A` (determined by `A[i]!=0`).\n"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@doc findn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{verbatim}\n",
       "findnz(A)\n",
       "\\end{verbatim}\n",
       "Return a tuple \\texttt{(I, J, V)} where \\texttt{I} and \\texttt{J} are the row and column indexes of the non-zero values in matrix \\texttt{A}, and \\texttt{V} is a vector of the non-zero values.\n"
      ],
      "text/markdown": [
       "```\n",
       "findnz(A)\n",
       "```\n",
       "\n",
       "Return a tuple `(I, J, V)` where `I` and `J` are the row and column indexes of the non-zero values in matrix `A`, and `V` is a vector of the non-zero values.\n"
      ],
      "text/plain": [
       "```\n",
       "findnz(A)\n",
       "```\n",
       "\n",
       "Return a tuple `(I, J, V)` where `I` and `J` are the row and column indexes of the non-zero values in matrix `A`, and `V` is a vector of the non-zero values.\n"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@doc findnz"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5x5 sparse matrix with 5 Float64 entries:\n",
       "\t[1, 1]  =  1.0\n",
       "\t[2, 2]  =  1.0\n",
       "\t[3, 3]  =  1.0\n",
       "\t[4, 4]  =  1.0\n",
       "\t[5, 5]  =  1.0"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sparse(eye(5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "issparse(speye(5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5x18 Array{Int64,2}:\n",
       " 0  0  0  1  0  0  0  0  0  0  0  0  0  0  0  0  0   0\n",
       " 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0   0\n",
       " 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  -5\n",
       " 0  0  0  0  0  0  2  0  0  0  0  0  0  0  0  0  0   0\n",
       " 0  0  0  0  0  0  0  0  3  0  0  0  0  0  0  0  0   0"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "full(S)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div class=\"section\" id=\"linear-algebra\">\n",
    "<h1>Linear algebra<a class=\"headerlink\" href=\"#linear-algebra\" title=\"Permalink to this headline\">¶</a></h1>\n",
    "<div class=\"section\" id=\"matrix-factorizations\">\n",
    "<h2>Matrix factorizations<a class=\"headerlink\" href=\"#matrix-factorizations\" title=\"Permalink to this headline\">¶</a></h2>\n",
    "<p><a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/Matrix_decomposition\">Matrix factorizations (a.k.a. matrix decompositions)</a>\n",
    "compute the factorization of a matrix into a product of matrices, and\n",
    "are one of the central concepts in linear algebra.</p>\n",
    "<p>The following table summarizes the types of matrix factorizations that have been\n",
    "implemented in Julia. Details of their associated methods can be found\n",
    "in the <a class=\"reference internal\" href=\"../../stdlib/linalg/#stdlib-linalg\"><span>Linear Algebra</span></a> section of the standard library documentation.</p>\n",
    "<div class=\"wy-table-responsive\"><table border=\"1\" class=\"docutils\">\n",
    "<colgroup>\n",
    "<col width=\"18%\">\n",
    "<col width=\"82%\">\n",
    "</colgroup>\n",
    "<tbody valign=\"top\">\n",
    "<tr class=\"row-odd\"><td><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">Cholesky</span></code></td>\n",
    "<td><a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/Cholesky_decomposition\">Cholesky factorization</a></td>\n",
    "</tr>\n",
    "<tr class=\"row-even\"><td><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">CholeskyPivoted</span></code></td>\n",
    "<td><a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/Pivot_element\">Pivoted</a> Cholesky factorization</td>\n",
    "</tr>\n",
    "<tr class=\"row-odd\"><td><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">LU</span></code></td>\n",
    "<td><a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/LU_decomposition\">LU factorization</a></td>\n",
    "</tr>\n",
    "<tr class=\"row-even\"><td><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">LUTridiagonal</span></code></td>\n",
    "<td>LU factorization for Tridiagonal matrices</td>\n",
    "</tr>\n",
    "<tr class=\"row-odd\"><td><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">UmfpackLU</span></code></td>\n",
    "<td>LU factorization for sparse matrices (computed by UMFPack)</td>\n",
    "</tr>\n",
    "<tr class=\"row-even\"><td><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">QR</span></code></td>\n",
    "<td><a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/QR_decomposition\">QR factorization</a></td>\n",
    "</tr>\n",
    "<tr class=\"row-odd\"><td><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">QRCompactWY</span></code></td>\n",
    "<td>Compact WY form of the QR factorization</td>\n",
    "</tr>\n",
    "<tr class=\"row-even\"><td><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">QRPivoted</span></code></td>\n",
    "<td>Pivoted <a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/QR_decomposition\">QR factorization</a></td>\n",
    "</tr>\n",
    "<tr class=\"row-odd\"><td><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">Hessenberg</span></code></td>\n",
    "<td><a class=\"reference external\" href=\"http://mathworld.wolfram.com/HessenbergDecomposition.html\">Hessenberg decomposition</a></td>\n",
    "</tr>\n",
    "<tr class=\"row-even\"><td><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">Eigen</span></code></td>\n",
    "<td><a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/Eigendecomposition_(matrix)\">Spectral decomposition</a></td>\n",
    "</tr>\n",
    "<tr class=\"row-odd\"><td><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">SVD</span></code></td>\n",
    "<td><a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/Singular_value_decomposition\">Singular value decomposition</a></td>\n",
    "</tr>\n",
    "<tr class=\"row-even\"><td><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">GeneralizedSVD</span></code></td>\n",
    "<td><a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/Generalized_singular_value_decomposition#Higher_order_version\">Generalized SVD</a></td>\n",
    "</tr>\n",
    "</tbody>\n",
    "</table></div>\n",
    "</div>\n",
    "<div class=\"section\" id=\"special-matrices\">\n",
    "<h2>Special matrices<a class=\"headerlink\" href=\"#special-matrices\" title=\"Permalink to this headline\">¶</a></h2>\n",
    "<p><a class=\"reference external\" href=\"http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=3274\">Matrices with special symmetries and structures</a>\n",
    "arise often in linear algebra and are frequently associated with\n",
    "various matrix factorizations.\n",
    "Julia features a rich collection of special matrix types, which allow for fast\n",
    "computation with specialized routines that are specially developed for\n",
    "particular matrix types.</p>\n",
    "<p>The following tables summarize the types of special matrices that have been\n",
    "implemented in Julia, as well as whether hooks to various optimized methods\n",
    "for them in LAPACK are available.</p>\n",
    "<div class=\"wy-table-responsive\"><table border=\"1\" class=\"docutils\">\n",
    "<colgroup>\n",
    "<col width=\"23%\">\n",
    "<col width=\"77%\">\n",
    "</colgroup>\n",
    "<tbody valign=\"top\">\n",
    "<tr class=\"row-odd\"><td><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">Hermitian</span></code></td>\n",
    "<td><a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/Hermitian_matrix\">Hermitian matrix</a></td>\n",
    "</tr>\n",
    "<tr class=\"row-even\"><td><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">UpperTriangular</span></code></td>\n",
    "<td>Upper <a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/Triangular_matrix\">triangular matrix</a></td>\n",
    "</tr>\n",
    "<tr class=\"row-odd\"><td><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">LowerTriangular</span></code></td>\n",
    "<td>Lower <a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/Triangular_matrix\">triangular matrix</a></td>\n",
    "</tr>\n",
    "<tr class=\"row-even\"><td><a class=\"reference internal\" href=\"../../stdlib/linalg/#Base.Tridiagonal\" title=\"Base.Tridiagonal\"><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">Tridiagonal</span></code></a></td>\n",
    "<td><a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/Tridiagonal_matrix\">Tridiagonal matrix</a></td>\n",
    "</tr>\n",
    "<tr class=\"row-odd\"><td><a class=\"reference internal\" href=\"../../stdlib/linalg/#Base.SymTridiagonal\" title=\"Base.SymTridiagonal\"><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">SymTridiagonal</span></code></a></td>\n",
    "<td>Symmetric tridiagonal matrix</td>\n",
    "</tr>\n",
    "<tr class=\"row-even\"><td><a class=\"reference internal\" href=\"../../stdlib/linalg/#Base.Bidiagonal\" title=\"Base.Bidiagonal\"><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">Bidiagonal</span></code></a></td>\n",
    "<td>Upper/lower <a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/Bidiagonal_matrix\">bidiagonal matrix</a></td>\n",
    "</tr>\n",
    "<tr class=\"row-odd\"><td><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">Diagonal</span></code></td>\n",
    "<td><a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/Diagonal_matrix\">Diagonal matrix</a></td>\n",
    "</tr>\n",
    "<tr class=\"row-even\"><td><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">UniformScaling</span></code></td>\n",
    "<td><a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/Uniform_scaling\">Uniform scaling operator</a></td>\n",
    "</tr>\n",
    "</tbody>\n",
    "</table></div>\n",
    "<div class=\"section\" id=\"elementary-operations\">\n",
    "<h3>Elementary operations<a class=\"headerlink\" href=\"#elementary-operations\" title=\"Permalink to this headline\">¶</a></h3>\n",
    "<div class=\"wy-table-responsive\"><table border=\"1\" class=\"docutils\">\n",
    "<colgroup>\n",
    "<col width=\"29%\">\n",
    "<col width=\"8%\">\n",
    "<col width=\"8%\">\n",
    "<col width=\"8%\">\n",
    "<col width=\"8%\">\n",
    "<col width=\"38%\">\n",
    "</colgroup>\n",
    "<thead valign=\"bottom\">\n",
    "<tr class=\"row-odd\"><th class=\"head\">Matrix type</th>\n",
    "<th class=\"head\"><code class=\"docutils literal\"><span class=\"pre\">+</span></code></th>\n",
    "<th class=\"head\"><code class=\"docutils literal\"><span class=\"pre\">-</span></code></th>\n",
    "<th class=\"head\"><code class=\"docutils literal\"><span class=\"pre\">*</span></code></th>\n",
    "<th class=\"head\"><code class=\"docutils literal\"><span class=\"pre\">\\</span></code></th>\n",
    "<th class=\"head\">Other functions with\n",
    "optimized methods</th>\n",
    "</tr>\n",
    "</thead>\n",
    "<tbody valign=\"top\">\n",
    "<tr class=\"row-even\"><td><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">Hermitian</span></code></td>\n",
    "<td>&nbsp;</td>\n",
    "<td>&nbsp;</td>\n",
    "<td>&nbsp;</td>\n",
    "<td>MV</td>\n",
    "<td><a class=\"reference internal\" href=\"../../stdlib/linalg/#Base.inv\" title=\"Base.inv\"><code class=\"xref jl jl-func docutils literal\"><span class=\"pre\">inv()</span></code></a>,\n",
    "<a class=\"reference internal\" href=\"../../stdlib/linalg/#Base.sqrtm\" title=\"Base.sqrtm\"><code class=\"xref jl jl-func docutils literal\"><span class=\"pre\">sqrtm()</span></code></a>, <a class=\"reference internal\" href=\"../../stdlib/linalg/#Base.expm\" title=\"Base.expm\"><code class=\"xref jl jl-func docutils literal\"><span class=\"pre\">expm()</span></code></a></td>\n",
    "</tr>\n",
    "<tr class=\"row-odd\"><td><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">UpperTriangular</span></code></td>\n",
    "<td>&nbsp;</td>\n",
    "<td>&nbsp;</td>\n",
    "<td>MV</td>\n",
    "<td>MV</td>\n",
    "<td><a class=\"reference internal\" href=\"../../stdlib/linalg/#Base.inv\" title=\"Base.inv\"><code class=\"xref jl jl-func docutils literal\"><span class=\"pre\">inv()</span></code></a>, <a class=\"reference internal\" href=\"../../stdlib/linalg/#Base.det\" title=\"Base.det\"><code class=\"xref jl jl-func docutils literal\"><span class=\"pre\">det()</span></code></a></td>\n",
    "</tr>\n",
    "<tr class=\"row-even\"><td><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">LowerTriangular</span></code></td>\n",
    "<td>&nbsp;</td>\n",
    "<td>&nbsp;</td>\n",
    "<td>MV</td>\n",
    "<td>MV</td>\n",
    "<td><a class=\"reference internal\" href=\"../../stdlib/linalg/#Base.inv\" title=\"Base.inv\"><code class=\"xref jl jl-func docutils literal\"><span class=\"pre\">inv()</span></code></a>, <a class=\"reference internal\" href=\"../../stdlib/linalg/#Base.det\" title=\"Base.det\"><code class=\"xref jl jl-func docutils literal\"><span class=\"pre\">det()</span></code></a></td>\n",
    "</tr>\n",
    "<tr class=\"row-odd\"><td><a class=\"reference internal\" href=\"../../stdlib/linalg/#Base.SymTridiagonal\" title=\"Base.SymTridiagonal\"><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">SymTridiagonal</span></code></a></td>\n",
    "<td>M</td>\n",
    "<td>M</td>\n",
    "<td>MS</td>\n",
    "<td>MV</td>\n",
    "<td><a class=\"reference internal\" href=\"../../stdlib/linalg/#Base.eigmax\" title=\"Base.eigmax\"><code class=\"xref jl jl-func docutils literal\"><span class=\"pre\">eigmax()</span></code></a>, <a class=\"reference internal\" href=\"../../stdlib/linalg/#Base.eigmin\" title=\"Base.eigmin\"><code class=\"xref jl jl-func docutils literal\"><span class=\"pre\">eigmin()</span></code></a></td>\n",
    "</tr>\n",
    "<tr class=\"row-even\"><td><a class=\"reference internal\" href=\"../../stdlib/linalg/#Base.Tridiagonal\" title=\"Base.Tridiagonal\"><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">Tridiagonal</span></code></a></td>\n",
    "<td>M</td>\n",
    "<td>M</td>\n",
    "<td>MS</td>\n",
    "<td>MV</td>\n",
    "<td>&nbsp;</td>\n",
    "</tr>\n",
    "<tr class=\"row-odd\"><td><a class=\"reference internal\" href=\"../../stdlib/linalg/#Base.Bidiagonal\" title=\"Base.Bidiagonal\"><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">Bidiagonal</span></code></a></td>\n",
    "<td>M</td>\n",
    "<td>M</td>\n",
    "<td>MS</td>\n",
    "<td>MV</td>\n",
    "<td>&nbsp;</td>\n",
    "</tr>\n",
    "<tr class=\"row-even\"><td><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">Diagonal</span></code></td>\n",
    "<td>M</td>\n",
    "<td>M</td>\n",
    "<td>MV</td>\n",
    "<td>MV</td>\n",
    "<td><a class=\"reference internal\" href=\"../../stdlib/linalg/#Base.inv\" title=\"Base.inv\"><code class=\"xref jl jl-func docutils literal\"><span class=\"pre\">inv()</span></code></a>, <a class=\"reference internal\" href=\"../../stdlib/linalg/#Base.det\" title=\"Base.det\"><code class=\"xref jl jl-func docutils literal\"><span class=\"pre\">det()</span></code></a>,\n",
    "<a class=\"reference internal\" href=\"../../stdlib/linalg/#Base.logdet\" title=\"Base.logdet\"><code class=\"xref jl jl-func docutils literal\"><span class=\"pre\">logdet()</span></code></a>, <a class=\"reference internal\" href=\"../../stdlib/math/#Base./\" title=\"Base./\"><code class=\"xref jl jl-func docutils literal\"><span class=\"pre\">/()</span></code></a></td>\n",
    "</tr>\n",
    "<tr class=\"row-odd\"><td><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">UniformScaling</span></code></td>\n",
    "<td>M</td>\n",
    "<td>M</td>\n",
    "<td>MVS</td>\n",
    "<td>MVS</td>\n",
    "<td><a class=\"reference internal\" href=\"../../stdlib/math/#Base./\" title=\"Base./\"><code class=\"xref jl jl-func docutils literal\"><span class=\"pre\">/()</span></code></a></td>\n",
    "</tr>\n",
    "</tbody>\n",
    "</table></div>\n",
    "<p>Legend:</p>\n",
    "<div class=\"wy-table-responsive\"><table border=\"1\" class=\"docutils\">\n",
    "<colgroup>\n",
    "<col width=\"16%\">\n",
    "<col width=\"84%\">\n",
    "</colgroup>\n",
    "<tbody valign=\"top\">\n",
    "<tr class=\"row-odd\"><td>M (matrix)</td>\n",
    "<td>An optimized method for matrix-matrix operations is available</td>\n",
    "</tr>\n",
    "<tr class=\"row-even\"><td>V (vector)</td>\n",
    "<td>An optimized method for matrix-vector operations is available</td>\n",
    "</tr>\n",
    "<tr class=\"row-odd\"><td>S (scalar)</td>\n",
    "<td>An optimized method for matrix-scalar operations is available</td>\n",
    "</tr>\n",
    "</tbody>\n",
    "</table></div>\n",
    "</div>\n",
    "<div class=\"section\" id=\"id3\">\n",
    "<h3>Matrix factorizations<a class=\"headerlink\" href=\"#id3\" title=\"Permalink to this headline\">¶</a></h3>\n",
    "<div class=\"wy-table-responsive\"><table border=\"1\" class=\"docutils\">\n",
    "<colgroup>\n",
    "<col width=\"23%\">\n",
    "<col width=\"7%\">\n",
    "<col width=\"12%\">\n",
    "<col width=\"15%\">\n",
    "<col width=\"15%\">\n",
    "<col width=\"12%\">\n",
    "<col width=\"15%\">\n",
    "</colgroup>\n",
    "<thead valign=\"bottom\">\n",
    "<tr class=\"row-odd\"><th class=\"head\">Matrix type</th>\n",
    "<th class=\"head\">LAPACK</th>\n",
    "<th class=\"head\"><a class=\"reference internal\" href=\"../../stdlib/linalg/#Base.eig\" title=\"Base.eig\"><code class=\"xref jl jl-func docutils literal\"><span class=\"pre\">eig()</span></code></a></th>\n",
    "<th class=\"head\"><a class=\"reference internal\" href=\"../../stdlib/linalg/#Base.eigvals\" title=\"Base.eigvals\"><code class=\"xref jl jl-func docutils literal\"><span class=\"pre\">eigvals()</span></code></a></th>\n",
    "<th class=\"head\"><a class=\"reference internal\" href=\"../../stdlib/linalg/#Base.eigvecs\" title=\"Base.eigvecs\"><code class=\"xref jl jl-func docutils literal\"><span class=\"pre\">eigvecs()</span></code></a></th>\n",
    "<th class=\"head\"><a class=\"reference internal\" href=\"../../stdlib/linalg/#Base.svd\" title=\"Base.svd\"><code class=\"xref jl jl-func docutils literal\"><span class=\"pre\">svd()</span></code></a></th>\n",
    "<th class=\"head\"><a class=\"reference internal\" href=\"../../stdlib/linalg/#Base.svdvals\" title=\"Base.svdvals\"><code class=\"xref jl jl-func docutils literal\"><span class=\"pre\">svdvals()</span></code></a></th>\n",
    "</tr>\n",
    "</thead>\n",
    "<tbody valign=\"top\">\n",
    "<tr class=\"row-even\"><td><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">Hermitian</span></code></td>\n",
    "<td>HE</td>\n",
    "<td>&nbsp;</td>\n",
    "<td>ARI</td>\n",
    "<td>&nbsp;</td>\n",
    "<td>&nbsp;</td>\n",
    "<td>&nbsp;</td>\n",
    "</tr>\n",
    "<tr class=\"row-odd\"><td><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">UpperTriangular</span></code></td>\n",
    "<td>TR</td>\n",
    "<td>A</td>\n",
    "<td>A</td>\n",
    "<td>A</td>\n",
    "<td>&nbsp;</td>\n",
    "<td>&nbsp;</td>\n",
    "</tr>\n",
    "<tr class=\"row-even\"><td><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">LowerTriangular</span></code></td>\n",
    "<td>TR</td>\n",
    "<td>A</td>\n",
    "<td>A</td>\n",
    "<td>A</td>\n",
    "<td>&nbsp;</td>\n",
    "<td>&nbsp;</td>\n",
    "</tr>\n",
    "<tr class=\"row-odd\"><td><a class=\"reference internal\" href=\"../../stdlib/linalg/#Base.SymTridiagonal\" title=\"Base.SymTridiagonal\"><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">SymTridiagonal</span></code></a></td>\n",
    "<td>ST</td>\n",
    "<td>A</td>\n",
    "<td>ARI</td>\n",
    "<td>AV</td>\n",
    "<td>&nbsp;</td>\n",
    "<td>&nbsp;</td>\n",
    "</tr>\n",
    "<tr class=\"row-even\"><td><a class=\"reference internal\" href=\"../../stdlib/linalg/#Base.Tridiagonal\" title=\"Base.Tridiagonal\"><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">Tridiagonal</span></code></a></td>\n",
    "<td>GT</td>\n",
    "<td>&nbsp;</td>\n",
    "<td>&nbsp;</td>\n",
    "<td>&nbsp;</td>\n",
    "<td>&nbsp;</td>\n",
    "<td>&nbsp;</td>\n",
    "</tr>\n",
    "<tr class=\"row-odd\"><td><a class=\"reference internal\" href=\"../../stdlib/linalg/#Base.Bidiagonal\" title=\"Base.Bidiagonal\"><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">Bidiagonal</span></code></a></td>\n",
    "<td>BD</td>\n",
    "<td>&nbsp;</td>\n",
    "<td>&nbsp;</td>\n",
    "<td>&nbsp;</td>\n",
    "<td>A</td>\n",
    "<td>A</td>\n",
    "</tr>\n",
    "<tr class=\"row-even\"><td><code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">Diagonal</span></code></td>\n",
    "<td>DI</td>\n",
    "<td>&nbsp;</td>\n",
    "<td>A</td>\n",
    "<td>&nbsp;</td>\n",
    "<td>&nbsp;</td>\n",
    "<td>&nbsp;</td>\n",
    "</tr>\n",
    "</tbody>\n",
    "</table></div>\n",
    "<p>Legend:</p>\n",
    "<div class=\"wy-table-responsive\"><table border=\"1\" class=\"docutils\">\n",
    "<colgroup>\n",
    "<col width=\"8%\">\n",
    "<col width=\"78%\">\n",
    "<col width=\"14%\">\n",
    "</colgroup>\n",
    "<tbody valign=\"top\">\n",
    "<tr class=\"row-odd\"><td>A (all)</td>\n",
    "<td>An optimized method to find all the characteristic values and/or vectors is available</td>\n",
    "<td>e.g. <code class=\"docutils literal\"><span class=\"pre\">eigvals(M)</span></code></td>\n",
    "</tr>\n",
    "<tr class=\"row-even\"><td>R (range)</td>\n",
    "<td>An optimized method to find the <code class=\"docutils literal\"><span class=\"pre\">il</span></code><sup>th</sup> through the <code class=\"docutils literal\"><span class=\"pre\">ih</span></code><sup>th</sup> characteristic values are available</td>\n",
    "<td><code class=\"docutils literal\"><span class=\"pre\">eigvals(M,</span> <span class=\"pre\">il,</span> <span class=\"pre\">ih)</span></code></td>\n",
    "</tr>\n",
    "<tr class=\"row-odd\"><td>I (interval)</td>\n",
    "<td>An optimized method to find the characteristic values in the interval [<code class=\"docutils literal\"><span class=\"pre\">vl</span></code>, <code class=\"docutils literal\"><span class=\"pre\">vh</span></code>] is available</td>\n",
    "<td><code class=\"docutils literal\"><span class=\"pre\">eigvals(M,</span> <span class=\"pre\">vl,</span> <span class=\"pre\">vh)</span></code></td>\n",
    "</tr>\n",
    "<tr class=\"row-even\"><td>V (vectors)</td>\n",
    "<td>An optimized method to find the characteristic vectors corresponding to the characteristic values <code class=\"docutils literal\"><span class=\"pre\">x=[x1,</span> <span class=\"pre\">x2,...]</span></code> is available</td>\n",
    "<td><code class=\"docutils literal\"><span class=\"pre\">eigvecs(M,</span> <span class=\"pre\">x)</span></code></td>\n",
    "</tr>\n",
    "</tbody>\n",
    "</table></div>\n",
    "</div>\n",
    "<div class=\"section\" id=\"the-uniform-scaling-operator\">\n",
    "<h3>The uniform scaling operator<a class=\"headerlink\" href=\"#the-uniform-scaling-operator\" title=\"Permalink to this headline\">¶</a></h3>\n",
    "<p>A <code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">UniformScaling</span></code> operator represents a scalar times the identity operator, <code class=\"docutils literal\"><span class=\"pre\">λ*I</span></code>. The identity operator  <code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">I</span></code> is defined as a constant and is an instance of <code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">UniformScaling</span></code>. The size of these operators are generic and match the other matrix in the binary operations <a class=\"reference internal\" href=\"../../stdlib/math/#Base.+\" title=\"Base.+\"><code class=\"xref jl jl-obj docutils literal\"><span class=\"pre\">+</span></code></a>, <a class=\"reference internal\" href=\"../../stdlib/math/#Base.-\" title=\"Base.-\"><code class=\"xref jl jl-obj docutils literal\"><span class=\"pre\">-</span></code></a>, <a class=\"reference internal\" href=\"../../stdlib/strings/#Base.*\" title=\"Base.*\"><code class=\"xref jl jl-obj docutils literal\"><span class=\"pre\">*</span></code></a> and <a class=\"reference internal\" href=\"../../stdlib/math/#Base.\\\" title=\"Base.\\\"><code class=\"xref jl jl-obj docutils literal\"><span class=\"pre\">\\</span></code></a>. For <code class=\"docutils literal\"><span class=\"pre\">A+I</span></code> and <code class=\"docutils literal\"><span class=\"pre\">A-I</span></code> this means that <code class=\"docutils literal\"><span class=\"pre\">A</span></code> must be square. Multiplication with the identity operator <code class=\"xref jl jl-class docutils literal\"><span class=\"pre\">I</span></code> is a noop (except for checking that the scaling factor is one) and therefore almost without overhead.</p>\n",
    "</div>\n",
    "</div>\n",
    "</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4-element Array{Int64,1}:\n",
       " 1\n",
       " 4\n",
       " 3\n",
       " 5"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "I"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello World"
     ]
    },
    {
     "data": {
      "text/plain": [
       "11"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "write(STDOUT,\"Hello World\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "read(STDIN,Char)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a"
     ]
    },
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "write(STDOUT,0x61)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "97"
     ]
    }
   ],
   "source": [
    "print(STDOUT,0x61)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "open(\"hello.txt\", \"w\") do f\n",
    "    write(f, \"Hello\")\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"HELLO\""
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "open(\"hello.txt\", \"r\") do f\n",
    "    uppercase(readall(f))\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "true"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "running = true"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Task (waiting) @0x0000000082e2b490"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@async begin\n",
    "    server = listen(2000)\n",
    "    while running\n",
    "       sock = accept(server)\n",
    "       println(\"Hello World\\n\")\n",
    "     end\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "TCPSocket(open, 0 bytes waiting)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello World\n",
      "\n"
     ]
    }
   ],
   "source": [
    "connect(2000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "false"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "running = false"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "TCPSocket(open, 0 bytes waiting)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello World\n",
      "\n"
     ]
    }
   ],
   "source": [
    "connect(2000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "TCPSocket(open, 0 bytes waiting)"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello World\n",
      "\n"
     ]
    }
   ],
   "source": [
    "connect(2000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Base.TCPServer(active)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "listen(ip\"127.0.0.1\",2000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Task (waiting) @0x00000000827b7490"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@async begin\n",
    "         server = listen(2001)\n",
    "         while true\n",
    "           sock = accept(server)\n",
    "           @async while isopen(sock)\n",
    "             write(sock,readline(sock))\n",
    "           end\n",
    "         end\n",
    "       end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "TCPSocket(open, 0 bytes waiting)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clientside=connect(2001)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Task (waiting) @0x00000000827b4010"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@async while true\n",
    "          write(STDOUT,readline(clientside))\n",
    "       end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello World from the Echo Server\n"
     ]
    }
   ],
   "source": [
    "println(clientside,\"Hello World from the Echo Server\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "ERROR (unhandled task failure): ArgumentError: stream is closed or unusable\n",
      " in check_open at stream.jl:329\n"
     ]
    }
   ],
   "source": [
    "close(clientside)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "TCPSocket(open, 0 bytes waiting)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clientside=connect(2001)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "ERROR (unhandled task failure): ArgumentError: stream is closed or unusable\n",
      " in check_open at stream.jl:329\n"
     ]
    }
   ],
   "source": [
    "close(clientside)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "ip\"192.30.252.131\""
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "getaddrinfo(\"github.com\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "LoadError",
     "evalue": "LoadError: no process with id 2 exists\nwhile loading In[10], in expression starting on line 1",
     "output_type": "error",
     "traceback": [
      "LoadError: no process with id 2 exists\nwhile loading In[10], in expression starting on line 1",
      ""
     ]
    }
   ],
   "source": [
    "r = remotecall(2, rand, 2, 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{verbatim}\n",
       "remotecall(id, func, args...)\n",
       "\\end{verbatim}\n",
       "Call a function asynchronously on the given arguments on the specified process. Returns a \\texttt{RemoteRef}.\n"
      ],
      "text/markdown": [
       "```\n",
       "remotecall(id, func, args...)\n",
       "```\n",
       "\n",
       "Call a function asynchronously on the given arguments on the specified process. Returns a `RemoteRef`.\n"
      ],
      "text/plain": [
       "```\n",
       "remotecall(id, func, args...)\n",
       "```\n",
       "\n",
       "Call a function asynchronously on the given arguments on the specified process. Returns a `RemoteRef`.\n"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@doc remotecall"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RemoteRef{Channel{Any}}(1,1,1)"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r = remotecall(1, rand, 2, 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2x2 Array{Float64,2}:\n",
       " 0.0962851  0.575182\n",
       " 0.317417   0.794743"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fetch(r)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RemoteRef{Channel{Any}}(1,1,2)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = @spawnat 1 1 .+ fetch(r)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2x2 Array{Float64,2}:\n",
       " 1.09629  1.57518\n",
       " 1.31742  1.79474"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fetch(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.09628513808182326"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "remotecall_fetch(1, getindex, r, 1, 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{verbatim}\n",
       "@everywhere\n",
       "\\end{verbatim}\n",
       "Execute an expression on all processes. Errors on any of the processes are collected into a \\texttt{CompositeException} and thrown.\n"
      ],
      "text/markdown": [
       "```\n",
       "@everywhere\n",
       "```\n",
       "\n",
       "Execute an expression on all processes. Errors on any of the processes are collected into a `CompositeException` and thrown.\n"
      ],
      "text/plain": [
       "```\n",
       "@everywhere\n",
       "```\n",
       "\n",
       "Execute an expression on all processes. Errors on any of the processes are collected into a `CompositeException` and thrown.\n"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@doc @everywhere"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A file can also be preloaded on multiple processes at startup, and a driver script can be used to drive the computation:\n",
    "\n",
    "```\n",
    "julia -p <n> -L file1.jl -L file2.jl driver.jl\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Functions addprocs(), rmprocs(), workers(), and others are available as a programmatic means of adding, removing and querying the processes in a cluster."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{verbatim}\n",
       "addprocs(machines; keyword_args...) -> List of process identifiers\n",
       "\\end{verbatim}\n",
       "Add processes on remote machines via SSH. Requires julia to be installed in the same location on each node, or to be available via a shared file system.\n",
       "\\texttt{machines} is a vector of machine specifications.  Worker are started for each specification.\n",
       "A machine specification is either a string \\texttt{machine_spec} or a tuple - \\texttt{(machine_spec, count)}.\n",
       "\\texttt{machine_spec} is a string of the form \\texttt{[user@]host[:port] [bind_addr[:port]]}. \\texttt{user} defaults to current user, \\texttt{port} to the standard ssh port. If \\texttt{[bind_addr[:port]]} is specified, other workers will connect to this worker at the specified \\texttt{bind_addr} and \\texttt{port}.\n",
       "\\texttt{count} is the number of workers to be launched on the specified host. If specified as \\texttt{:auto} it will launch as many workers as the number of cores on the specific host.\n",
       "Keyword arguments:\n",
       "\\begin{itemize}\n",
       "\\item \\texttt{tunnel}: if \\texttt{true} then SSH tunneling will be used to connect to the worker from the             master process. Default is \\texttt{false}.\n",
       "\\end{itemize}\n",
       "\\begin{itemize}\n",
       "\\item \\texttt{sshflags}: specifies additional ssh options, e.g.\n",
       "\\end{itemize}\n",
       "\\begin{verbatim}\n",
       "sshflags=`-i /home/foo/bar.pem`\n",
       "\\end{verbatim}\n",
       "\\begin{itemize}\n",
       "\\item \\texttt{max_parallel}: specifies the maximum number of workers connected to in parallel at a host.                   Defaults to 10.\n",
       "\\end{itemize}\n",
       "\\begin{itemize}\n",
       "\\item \\texttt{dir}: specifies the working directory on the workers. Defaults to the host's current          directory (as found by \\texttt{pwd()})\n",
       "\\end{itemize}\n",
       "\\begin{itemize}\n",
       "\\item \\texttt{exename}: name of the julia executable. Defaults to \\texttt{\"$JULIA_HOME/julia\"} or              \\texttt{\"$JULIA_HOME/julia-debug\"} as the case may be.\n",
       "\\end{itemize}\n",
       "\\begin{itemize}\n",
       "\\item \\texttt{exeflags}: additional flags passed to the worker processes.\n",
       "\\end{itemize}\n",
       "\\begin{itemize}\n",
       "\\item \\texttt{topology}: Specifies how the workers connect to each other. Sending a message             between unconnected workers results in an error.\n",
       "\\end{itemize}\n",
       "\\begin{itemize}\n",
       "\\item \\texttt{topology=:all_to_all}  :  All processes are connected to each other.                       This is the default.\n",
       "\\end{itemize}\n",
       "\\begin{itemize}\n",
       "\\item \\texttt{topology=:master_slave}  :  Only the driver process, i.e. pid 1 connects to the                         workers. The workers do not connect to each other.\n",
       "\\end{itemize}\n",
       "\\begin{itemize}\n",
       "\\item \\texttt{topology=:custom}  :  The \\texttt{launch} method of the cluster manager specifes the                   connection topology via fields \\texttt{ident} and \\texttt{connect_idents} in                   \\texttt{WorkerConfig}. A worker with a cluster manager identity \\texttt{ident}                   will connect to all workers specified in \\texttt{connect_idents}.\n",
       "\\end{itemize}\n",
       "Environment variables :\n",
       "If the master process fails to establish a connection with a newly launched worker within 60.0 seconds, the worker treats it a fatal situation and terminates. This timeout can be controlled via environment variable \\texttt{JULIA_WORKER_TIMEOUT}. The value of \\texttt{JULIA_WORKER_TIMEOUT} on the master process, specifies the number of seconds a newly launched worker waits for connection establishment.\n",
       "\\begin{verbatim}\n",
       "..  addprocs(manager::ClusterManager; kwargs...) -> List of process identifiers\n",
       "\n",
       "Launches worker processes via the specified cluster manager.\n",
       "\n",
       "For example Beowulf clusters are  supported via a custom cluster manager implemented in package ``ClusterManagers``.\n",
       "\n",
       "The number of seconds a newly launched worker waits for connection establishment from the master can be\n",
       "specified via variable ``JULIA_WORKER_TIMEOUT`` in the worker process's environment. Relevant only when using TCP/IP as transport.\n",
       "\\end{verbatim}\n",
       "\\begin{verbatim}\n",
       "..  addprocs(n::Integer; exeflags=``) -> List of process identifiers\n",
       "\n",
       "Launches workers using the in-built ``LocalManager`` which only launches workers on the local host.\n",
       "This can be used to take advantage of multiple cores. ``addprocs(4)`` will add 4 processes on the local machine.\n",
       "\\end{verbatim}\n",
       "\\begin{verbatim}\n",
       "..  addprocs() -> List of process identifiers\n",
       "\n",
       "Equivalent to ``addprocs(CPU_CORES)``\n",
       "\n",
       "Note that workers do not run a ``.juliarc.jl`` startup script, nor do they synchronize their global state\n",
       "(such as global variables, new method definitions, and loaded modules) with any of the other running processes.\n",
       "\\end{verbatim}\n"
      ],
      "text/markdown": [
       "```\n",
       "addprocs(machines; keyword_args...) -> List of process identifiers\n",
       "```\n",
       "\n",
       "Add processes on remote machines via SSH. Requires julia to be installed in the same location on each node, or to be available via a shared file system.\n",
       "\n",
       "`machines` is a vector of machine specifications.  Worker are started for each specification.\n",
       "\n",
       "A machine specification is either a string `machine_spec` or a tuple - `(machine_spec, count)`.\n",
       "\n",
       "`machine_spec` is a string of the form `[user@]host[:port] [bind_addr[:port]]`. `user` defaults to current user, `port` to the standard ssh port. If `[bind_addr[:port]]` is specified, other workers will connect to this worker at the specified `bind_addr` and `port`.\n",
       "\n",
       "`count` is the number of workers to be launched on the specified host. If specified as `:auto` it will launch as many workers as the number of cores on the specific host.\n",
       "\n",
       "Keyword arguments:\n",
       "\n",
       "  * `tunnel`: if `true` then SSH tunneling will be used to connect to the worker from the             master process. Default is `false`.\n",
       "\n",
       "  * `sshflags`: specifies additional ssh options, e.g.\n",
       "\n",
       "```\n",
       "sshflags=`-i /home/foo/bar.pem`\n",
       "```\n",
       "\n",
       "  * `max_parallel`: specifies the maximum number of workers connected to in parallel at a host.                   Defaults to 10.\n",
       "\n",
       "  * `dir`: specifies the working directory on the workers. Defaults to the host's current          directory (as found by `pwd()`)\n",
       "\n",
       "  * `exename`: name of the julia executable. Defaults to `\"$JULIA_HOME/julia\"` or              `\"$JULIA_HOME/julia-debug\"` as the case may be.\n",
       "\n",
       "  * `exeflags`: additional flags passed to the worker processes.\n",
       "\n",
       "  * `topology`: Specifies how the workers connect to each other. Sending a message             between unconnected workers results in an error.\n",
       "\n",
       "  * `topology=:all_to_all`  :  All processes are connected to each other.                       This is the default.\n",
       "\n",
       "  * `topology=:master_slave`  :  Only the driver process, i.e. pid 1 connects to the                         workers. The workers do not connect to each other.\n",
       "\n",
       "  * `topology=:custom`  :  The `launch` method of the cluster manager specifes the                   connection topology via fields `ident` and `connect_idents` in                   `WorkerConfig`. A worker with a cluster manager identity `ident`                   will connect to all workers specified in `connect_idents`.\n",
       "\n",
       "Environment variables :\n",
       "\n",
       "If the master process fails to establish a connection with a newly launched worker within 60.0 seconds, the worker treats it a fatal situation and terminates. This timeout can be controlled via environment variable `JULIA_WORKER_TIMEOUT`. The value of `JULIA_WORKER_TIMEOUT` on the master process, specifies the number of seconds a newly launched worker waits for connection establishment.\n",
       "\n",
       "```rst\n",
       "..  addprocs(manager::ClusterManager; kwargs...) -> List of process identifiers\n",
       "\n",
       "Launches worker processes via the specified cluster manager.\n",
       "\n",
       "For example Beowulf clusters are  supported via a custom cluster manager implemented in package ``ClusterManagers``.\n",
       "\n",
       "The number of seconds a newly launched worker waits for connection establishment from the master can be\n",
       "specified via variable ``JULIA_WORKER_TIMEOUT`` in the worker process's environment. Relevant only when using TCP/IP as transport.\n",
       "```\n",
       "\n",
       "```rst\n",
       "..  addprocs(n::Integer; exeflags=``) -> List of process identifiers\n",
       "\n",
       "Launches workers using the in-built ``LocalManager`` which only launches workers on the local host.\n",
       "This can be used to take advantage of multiple cores. ``addprocs(4)`` will add 4 processes on the local machine.\n",
       "```\n",
       "\n",
       "```rst\n",
       "..  addprocs() -> List of process identifiers\n",
       "\n",
       "Equivalent to ``addprocs(CPU_CORES)``\n",
       "\n",
       "Note that workers do not run a ``.juliarc.jl`` startup script, nor do they synchronize their global state\n",
       "(such as global variables, new method definitions, and loaded modules) with any of the other running processes.\n",
       "```\n"
      ],
      "text/plain": [
       "```\n",
       "addprocs(machines; keyword_args...) -> List of process identifiers\n",
       "```\n",
       "\n",
       "Add processes on remote machines via SSH. Requires julia to be installed in the same location on each node, or to be available via a shared file system.\n",
       "\n",
       "`machines` is a vector of machine specifications.  Worker are started for each specification.\n",
       "\n",
       "A machine specification is either a string `machine_spec` or a tuple - `(machine_spec, count)`.\n",
       "\n",
       "`machine_spec` is a string of the form `[user@]host[:port] [bind_addr[:port]]`. `user` defaults to current user, `port` to the standard ssh port. If `[bind_addr[:port]]` is specified, other workers will connect to this worker at the specified `bind_addr` and `port`.\n",
       "\n",
       "`count` is the number of workers to be launched on the specified host. If specified as `:auto` it will launch as many workers as the number of cores on the specific host.\n",
       "\n",
       "Keyword arguments:\n",
       "\n",
       "  * `tunnel`: if `true` then SSH tunneling will be used to connect to the worker from the             master process. Default is `false`.\n",
       "\n",
       "  * `sshflags`: specifies additional ssh options, e.g.\n",
       "\n",
       "```\n",
       "sshflags=`-i /home/foo/bar.pem`\n",
       "```\n",
       "\n",
       "  * `max_parallel`: specifies the maximum number of workers connected to in parallel at a host.                   Defaults to 10.\n",
       "\n",
       "  * `dir`: specifies the working directory on the workers. Defaults to the host's current          directory (as found by `pwd()`)\n",
       "\n",
       "  * `exename`: name of the julia executable. Defaults to `\"$JULIA_HOME/julia\"` or              `\"$JULIA_HOME/julia-debug\"` as the case may be.\n",
       "\n",
       "  * `exeflags`: additional flags passed to the worker processes.\n",
       "\n",
       "  * `topology`: Specifies how the workers connect to each other. Sending a message             between unconnected workers results in an error.\n",
       "\n",
       "  * `topology=:all_to_all`  :  All processes are connected to each other.                       This is the default.\n",
       "\n",
       "  * `topology=:master_slave`  :  Only the driver process, i.e. pid 1 connects to the                         workers. The workers do not connect to each other.\n",
       "\n",
       "  * `topology=:custom`  :  The `launch` method of the cluster manager specifes the                   connection topology via fields `ident` and `connect_idents` in                   `WorkerConfig`. A worker with a cluster manager identity `ident`                   will connect to all workers specified in `connect_idents`.\n",
       "\n",
       "Environment variables :\n",
       "\n",
       "If the master process fails to establish a connection with a newly launched worker within 60.0 seconds, the worker treats it a fatal situation and terminates. This timeout can be controlled via environment variable `JULIA_WORKER_TIMEOUT`. The value of `JULIA_WORKER_TIMEOUT` on the master process, specifies the number of seconds a newly launched worker waits for connection establishment.\n",
       "\n",
       "```rst\n",
       "..  addprocs(manager::ClusterManager; kwargs...) -> List of process identifiers\n",
       "\n",
       "Launches worker processes via the specified cluster manager.\n",
       "\n",
       "For example Beowulf clusters are  supported via a custom cluster manager implemented in package ``ClusterManagers``.\n",
       "\n",
       "The number of seconds a newly launched worker waits for connection establishment from the master can be\n",
       "specified via variable ``JULIA_WORKER_TIMEOUT`` in the worker process's environment. Relevant only when using TCP/IP as transport.\n",
       "```\n",
       "\n",
       "```rst\n",
       "..  addprocs(n::Integer; exeflags=``) -> List of process identifiers\n",
       "\n",
       "Launches workers using the in-built ``LocalManager`` which only launches workers on the local host.\n",
       "This can be used to take advantage of multiple cores. ``addprocs(4)`` will add 4 processes on the local machine.\n",
       "```\n",
       "\n",
       "```rst\n",
       "..  addprocs() -> List of process identifiers\n",
       "\n",
       "Equivalent to ``addprocs(CPU_CORES)``\n",
       "\n",
       "Note that workers do not run a ``.juliarc.jl`` startup script, nor do they synchronize their global state\n",
       "(such as global variables, new method definitions, and loaded modules) with any of the other running processes.\n",
       "```\n"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@doc addprocs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4-element Array{Int64,1}:\n",
       " 2\n",
       " 3\n",
       " 4\n",
       " 5"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "addprocs(CPU_CORES)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{verbatim}\n",
       "rmprocs(pids...)\n",
       "\\end{verbatim}\n",
       "Removes the specified workers.\n"
      ],
      "text/markdown": [
       "```\n",
       "rmprocs(pids...)\n",
       "```\n",
       "\n",
       "Removes the specified workers.\n"
      ],
      "text/plain": [
       "```\n",
       "rmprocs(pids...)\n",
       "```\n",
       "\n",
       "Removes the specified workers.\n"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@doc rmprocs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       ":ok"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rmprocs(2:5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{verbatim}\n",
       "workers()\n",
       "\\end{verbatim}\n",
       "Returns a list of all worker process identifiers.\n"
      ],
      "text/markdown": [
       "```\n",
       "workers()\n",
       "```\n",
       "\n",
       "Returns a list of all worker process identifiers.\n"
      ],
      "text/plain": [
       "```\n",
       "workers()\n",
       "```\n",
       "\n",
       "Returns a list of all worker process identifiers.\n"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@doc workers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1-element Array{Int64,1}:\n",
       " 1"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "workers()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1-element Array{Int64,1}:\n",
       " 6"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "addprocs(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1000x1000 Array{Float64,2}:\n",
       " 246.404  242.221  238.032  254.706  …  243.282  245.487  252.118  241.057\n",
       " 243.339  240.513  234.222  250.723     237.769  238.703  250.145  245.079\n",
       " 250.637  255.786  242.935  257.452     247.73   245.781  262.319  248.367\n",
       " 243.908  242.856  230.648  255.754     238.263  231.553  254.253  239.455\n",
       " 244.036  238.761  229.236  251.831     242.485  237.91   247.073  237.546\n",
       " 254.596  242.011  239.943  253.43   …  243.616  241.755  255.826  245.333\n",
       " 248.791  243.126  240.897  256.155     237.722  242.708  255.275  243.837\n",
       " 259.934  249.063  245.371  257.475     248.154  247.738  253.799  251.775\n",
       " 255.142  257.627  238.962  258.874     247.536  250.887  262.788  250.339\n",
       " 258.439  246.099  239.835  258.725     246.266  247.585  256.336  250.304\n",
       " 251.8    249.872  243.343  263.129  …  243.956  246.421  258.376  248.238\n",
       " 254.33   252.212  244.981  266.164     249.301  247.607  260.646  251.5  \n",
       " 239.953  238.257  231.743  248.553     234.31   236.973  245.512  242.757\n",
       "   ⋮                                 ⋱                                    \n",
       " 251.985  246.712  244.032  259.113     247.198  245.376  255.362  246.29 \n",
       " 241.387  237.25   227.91   246.957     231.149  234.83   243.936  237.991\n",
       " 247.982  239.343  242.975  252.364  …  242.299  243.514  253.694  244.807\n",
       " 246.281  240.536  235.542  254.281     241.636  239.819  254.562  248.062\n",
       " 240.949  240.212  228.712  252.72      233.891  241.514  244.912  238.206\n",
       " 249.677  241.039  238.226  255.855     245.584  242.288  254.834  240.649\n",
       " 258.221  255.998  243.612  265.073     252.986  251.552  256.02   250.876\n",
       " 255.235  254.157  244.438  260.01   …  246.602  247.79   261.32   256.728\n",
       " 258.449  255.126  241.177  262.322     251.234  247.363  265.31   255.299\n",
       " 246.749  241.591  234.83   252.649     239.62   242.041  250.532  244.319\n",
       " 249.495  252.653  241.14   260.425     247.769  243.989  254.85   249.385\n",
       " 256.806  249.05   238.676  254.243     250.715  244.72   256.024  248.573"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A = rand(1000,1000)\n",
    "Bref = @spawn A^2\n",
    "fetch(Bref)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1000x1000 Array{Float64,2}:\n",
       " 251.595  254.33   247.193  252.501  …  248.91   258.599  244.762  247.464\n",
       " 250.565  248.217  246.03   258.234     247.108  260.579  244.798  255.41 \n",
       " 260.231  258.129  257.54   261.643     255.022  268.091  253.707  258.482\n",
       " 261.73   252.601  258.425  259.525     252.993  264.234  246.043  251.129\n",
       " 250.694  248.909  251.479  258.033     251.815  260.496  246.965  250.312\n",
       " 254.487  256.475  257.219  258.062  …  252.266  265.012  249.896  251.187\n",
       " 264.973  262.663  253.166  265.109     258.167  267.081  252.323  259.728\n",
       " 255.139  255.575  253.545  251.209     248.798  256.714  241.387  243.304\n",
       " 248.275  248.251  244.467  250.769     244.57   256.027  243.599  244.343\n",
       " 251.918  254.828  249.018  257.571     251.384  258.705  249.207  251.484\n",
       " 249.905  250.095  252.897  252.255  …  250.972  261.598  245.073  255.24 \n",
       " 258.952  258.266  253.873  263.242     260.085  263.137  256.564  255.885\n",
       " 260.467  259.49   253.134  263.376     254.741  262.654  249.372  255.604\n",
       "   ⋮                                 ⋱                                    \n",
       " 251.179  247.748  247.126  253.16      250.674  257.49   244.074  245.429\n",
       " 258.505  254.735  250.735  261.631     253.725  264.102  251.939  254.412\n",
       " 254.342  254.287  248.055  247.69   …  244.079  258.708  248.105  248.718\n",
       " 249.458  245.795  251.603  248.344     245.072  253.275  239.518  238.998\n",
       " 255.037  250.388  249.593  257.99      250.008  258.415  248.764  245.302\n",
       " 260.354  253.519  250.388  261.4       253.847  262.321  249.825  253.66 \n",
       " 250.958  254.052  253.002  260.023     247.009  257.92   250.149  253.321\n",
       " 258.911  258.788  260.826  260.788  …  257.425  267.35   259.65   260.313\n",
       " 248.889  255.415  251.825  256.738     247.799  264.224  248.672  250.647\n",
       " 250.901  252.492  245.985  257.337     246.684  255.26   247.935  245.354\n",
       " 253.665  253.649  242.45   251.805     248.893  252.77   245.057  247.608\n",
       " 251.039  251.621  254.743  254.528     253.081  259.847  250.169  249.423"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Bref = @spawn rand(1000,1000)^2\n",
    "fetch(Bref)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "@everywhere function count_heads(n)\n",
    "    c::Int = 0\n",
    "    for i=1:n\n",
    "        c += rand(Bool)\n",
    "    end\n",
    "    c\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "99986694"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = @spawn count_heads(100000000)\n",
    "b = @spawn count_heads(100000000)\n",
    "fetch(a)+fetch(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "99987084"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nheads = @parallel (+) for i=1:200000000\n",
    "  Int(rand(Bool))\n",
    "end"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Using “outside” variables in parallel loops is perfectly reasonable if the variables are read-only:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "98074.77751656536"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = randn(1000)\n",
    "f = (x) -> x + 1\n",
    "@parallel (+) for i=1:100000\n",
    "  f(a[rand(1:end)])\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10-element Array{Any,1}:\n",
       " (\n",
       "1000x1000 Array{Float64,2}:\n",
       " -0.0315076  -0.00394116   0.0152079    …   0.0559766   -0.0285426 \n",
       " -0.0315637  -0.0107547   -0.00628968       0.0284223   -0.0173019 \n",
       " -0.0320324  -0.0184949   -0.0250978       -0.0190912    0.00138123\n",
       " -0.0314264   0.00468772   0.0325694        0.0037514    0.0455322 \n",
       " -0.0320306  -0.0151644   -0.0186629       -0.0225571   -0.0254369 \n",
       " -0.0314197   0.0113611   -0.000590949  …  -0.0322469   -0.00495385\n",
       " -0.0315449   0.0406572    0.0304707        0.0444839   -0.0188762 \n",
       " -0.0319561   0.0423949    2.5135e-5        0.0177694   -0.00352942\n",
       " -0.0317524  -0.00495734   0.0261374       -0.037082    -0.0116135 \n",
       " -0.0328785  -0.0187632    0.0179927       -0.0138243   -0.0395738 \n",
       " -0.0317036  -0.0566868   -0.0353252    …   0.068039    -0.0230809 \n",
       " -0.0316762  -0.0128482    0.0308106       -0.0625659    0.0237697 \n",
       " -0.0318716  -0.00144806   0.033064        -0.00426291   0.0150939 \n",
       "  ⋮                                     ⋱                          \n",
       " -0.0322185   0.0165      -0.0200463        0.00525218   0.0551763 \n",
       " -0.0313118   0.00816003   0.0213329        0.0182953    0.0229839 \n",
       " -0.0317269   0.0562589   -0.0624505    …   0.0307722    0.0204416 \n",
       " -0.0309255  -0.0451962   -0.0157127        0.0119718   -0.0031531 \n",
       " -0.0313113  -0.00891258  -0.0375671       -0.0262898    0.01854   \n",
       " -0.0308739   0.0312588   -0.017244        -0.00583114  -0.0447455 \n",
       " -0.031074    0.0382753    0.0218454       -0.0132529    0.0451067 \n",
       " -0.033338    0.00602266   0.0252348    …   0.0136868   -0.0174889 \n",
       " -0.0310656  -0.0266702   -0.016436         0.0214547   -0.0182285 \n",
       " -0.031242    0.0219562    0.00621808      -0.0257647    0.0376388 \n",
       " -0.0315242   0.0285014   -0.0647479       -0.00650076  -0.0425272 \n",
       " -0.031818    0.0294657    0.0350669        0.0370064   -0.042589  ,\n",
       "\n",
       "[500.078,18.2116,18.1256,18.0308,17.9203,17.8838,17.7771,17.7282,17.6893,17.6449  …  0.125908,0.111749,0.0975661,0.0871337,0.0764787,0.0616545,0.0513208,0.0327209,0.0215172,0.00618509],\n",
       "1000x1000 Array{Float64,2}:\n",
       " -0.0321022   0.0125305   -0.0379696    …   0.0302175     0.0209978 \n",
       " -0.0312126   0.026984     0.0290173        0.0285233    -0.0920189 \n",
       " -0.0325228  -0.0163886    0.0231622       -0.0277859    -0.0376601 \n",
       " -0.0318726   0.00379603   0.0114026        0.00431671    0.0286438 \n",
       " -0.0314643   0.0213968    0.04075         -0.0498138     0.02521   \n",
       " -0.0306719   0.0203558   -0.0352077    …  -0.00810685    0.00414028\n",
       " -0.0307735   0.00272036  -0.00768623      -0.0189556    -0.0340436 \n",
       " -0.0314703   0.0414934   -0.0263514        0.0360221    -0.00789824\n",
       " -0.0318822   0.00349579  -0.051908        -0.0435776     0.0331852 \n",
       " -0.0305805   0.0474127   -0.0283175        0.0328199    -0.00600489\n",
       " -0.0324702   0.014295    -0.0146088    …  -0.006769      0.0154264 \n",
       " -0.0310654  -0.040948    -0.0286198       -0.010489     -0.00698593\n",
       " -0.0319896  -0.0581159   -0.0711226        0.0284807     0.0207051 \n",
       "  ⋮                                     ⋱                           \n",
       " -0.0317756  -0.0131395   -0.0173488        0.0276041    -0.017685  \n",
       " -0.0325533  -0.0617124    0.0109088       -0.000187059  -0.0317461 \n",
       " -0.0319628  -0.0063972   -0.0327233    …  -0.0121039     0.0178259 \n",
       " -0.0313488   0.0553619    0.000414503      0.0279295     0.00224771\n",
       " -0.0314997   0.0652608    0.00948205       0.0280437    -0.0199604 \n",
       " -0.0318132  -0.00374133   0.0511152        0.0717837    -0.00520064\n",
       " -0.0311504  -0.032205     0.00664681       0.0464839     0.0216108 \n",
       " -0.0315776   0.0097719   -0.0594107    …  -0.00926987   -0.0374131 \n",
       " -0.0324715  -0.0100932    0.00995832      -0.0338846     0.0193121 \n",
       " -0.0320531  -0.0196288    0.0582223        0.00147772    0.00283298\n",
       " -0.0311122  -0.0638033    0.0213591       -0.0116204     0.0236912 \n",
       " -0.0306413   0.0624477   -0.038788         0.0366932     0.0694174 )                                                \n",
       " (\n",
       "1000x1000 Array{Float64,2}:\n",
       " -0.031557    0.000809726   0.0425272   …   0.00189846   0.0260888 \n",
       " -0.0308023   0.0196923     0.0117304      -0.00966993   0.04579   \n",
       " -0.0306265  -0.0348289     0.0210133      -0.0259416    0.0146443 \n",
       " -0.0326539  -0.0455918    -0.0319635      -0.0353741   -0.0416734 \n",
       " -0.0311372  -0.0200775    -0.0359903       0.00848781   0.00414307\n",
       " -0.0318315  -0.0159663    -0.0212469   …   0.029011    -0.01009   \n",
       " -0.0312407  -0.00659232   -0.00479347      0.0115306   -0.0185008 \n",
       " -0.0315681   0.0148979     0.031864        0.0102818    0.0331084 \n",
       " -0.0304966  -0.0233305     0.0520341       0.0202252   -0.0117715 \n",
       " -0.0324375  -0.016741      0.0489545       0.0297409   -0.0181066 \n",
       " -0.0317083  -0.0232255    -0.0888333   …  -0.0125819    0.0155961 \n",
       " -0.0315541   0.0328582     0.0171883       0.0239055    0.0276558 \n",
       " -0.0315724  -0.0148754     0.0194482      -0.0498967    0.016641  \n",
       "  ⋮                                     ⋱                          \n",
       " -0.0320811   0.0269917    -0.0668625       0.00275912  -0.0523007 \n",
       " -0.031869   -0.012895      0.0279492      -0.055544    -0.0156635 \n",
       " -0.0313654  -0.0244134    -0.0422854   …   0.0266855   -0.025834  \n",
       " -0.0328418   0.0040094     0.00188551     -0.00468431  -0.0110108 \n",
       " -0.0315265  -0.014648     -0.00201023      0.0330393    0.00775819\n",
       " -0.0323802   0.0153614     0.0681191      -0.0349856    0.0822445 \n",
       " -0.0319539   0.0257984    -0.0266217      -0.0144766    0.0318933 \n",
       " -0.0315634  -0.0159416    -0.0226942   …   0.0395155   -0.0383682 \n",
       " -0.0322324   0.0333303    -0.0420694      -0.0285821   -0.0667933 \n",
       " -0.0320952  -0.0167283    -0.0112928       0.0395484   -0.00446055\n",
       " -0.0317135  -0.0184464     0.0809096       0.0043491    0.0408432 \n",
       " -0.031171   -0.0529677     0.00186183      0.00279767   0.0135637 ,\n",
       "\n",
       "[500.395,18.2141,18.0274,17.9565,17.906,17.8287,17.7876,17.7266,17.6374,17.603  …  0.129974,0.122283,0.0935079,0.0924594,0.0701529,0.0601114,0.0401296,0.0249021,0.0125487,0.00587976],\n",
       "1000x1000 Array{Float64,2}:\n",
       " -0.0317983  -0.0268214    0.006167     …   0.0325403    0.0117969  \n",
       " -0.0329574  -0.028161     0.00114836      -0.0100315   -0.000168175\n",
       " -0.0314555   0.0178818   -0.0234348       -0.00669     -0.0852728  \n",
       " -0.0319125  -0.0503363    0.0336986       -0.00323489   0.0256359  \n",
       " -0.0312301   0.0366113    0.015047        -0.0126038    0.0291512  \n",
       " -0.0325283   0.0248081    0.0296879    …  -0.0340952    0.0200699  \n",
       " -0.0295127  -0.0247109    0.0185352        0.0286824   -0.00172437 \n",
       " -0.0317683   0.0123171    0.00836527       0.0248073   -0.0199029  \n",
       " -0.0320157   0.0357404    0.000661759     -0.0738432    0.0439522  \n",
       " -0.0309156   0.0409218    0.00320615       0.0129139   -0.040532   \n",
       " -0.032073   -0.0494123    0.0114987    …  -0.0380306   -0.000768886\n",
       " -0.0311     -0.0275052   -0.0818356        0.00485796   0.0316721  \n",
       " -0.0317746  -0.0574391    0.0144781       -0.0143499    0.0044058  \n",
       "  ⋮                                     ⋱                           \n",
       " -0.0319861   0.0179196   -0.0337763        0.0103865   -0.0576365  \n",
       " -0.0319748   0.0165166   -0.00916954      -0.0178959   -0.0376451  \n",
       " -0.0316738   0.0241889   -0.004005     …   0.0111851    0.0545147  \n",
       " -0.0317992  -0.00684388  -0.00564003       0.0121008   -0.00262623 \n",
       " -0.0317589   0.049606     0.0219306       -0.00755596  -0.00848859 \n",
       " -0.0313821   0.0131994    0.0388193       -0.00708719   0.00547208 \n",
       " -0.0313058   0.0391574    0.0131313       -0.0430989   -0.0554414  \n",
       " -0.0325822   0.0171259   -0.030388     …   0.0336817    0.00727338 \n",
       " -0.0318821  -0.019732    -0.00519187      -0.00077444  -0.00194128 \n",
       " -0.0318859   0.027801    -0.0301998        0.031169    -0.0190829  \n",
       " -0.0311901   0.0155775   -0.0142834       -0.0524959    0.0379099  \n",
       " -0.0321048  -0.0121762   -0.00570517       0.0283391   -0.0102456  )                                                  \n",
       " (\n",
       "1000x1000 Array{Float64,2}:\n",
       " -0.0314434  -0.0199186    0.0282312   …   0.00393603   0.00983636\n",
       " -0.031417    0.083845    -0.0220263      -0.0726024    0.0279476 \n",
       " -0.0323292  -0.00549819  -0.0127762      -0.0217685    0.016697  \n",
       " -0.0316943   0.0108053   -0.0395658       0.0110868   -0.0441592 \n",
       " -0.0312875   0.00220478   0.0465343      -0.0261228    0.00396805\n",
       " -0.0311767  -0.0202222    0.0631626   …   0.0126775   -0.0276189 \n",
       " -0.0318256  -0.00610205  -0.0113687       0.0206423   -0.0236173 \n",
       " -0.0323789   0.0301817    0.0355916       0.0461506    0.0448634 \n",
       " -0.0315768   0.00233143   0.0447515       0.0153171    0.0612859 \n",
       " -0.0312338   0.0198569    0.0389874       0.0514996   -0.0014599 \n",
       " -0.0322648   0.043873     0.0180339   …  -0.0691276   -0.00685685\n",
       " -0.029701    0.0152194    0.00127234      0.0378202   -0.036429  \n",
       " -0.0312402  -0.0325817    0.0188224      -0.0197274   -0.013216  \n",
       "  ⋮                                    ⋱                          \n",
       " -0.0312917  -0.0249343    0.0115052      -0.0333592   -0.0726567 \n",
       " -0.030909   -0.0591007    0.0774181       0.0267962    0.0265446 \n",
       " -0.0312343   0.0123066   -0.00969192  …  -0.0265291    0.0401165 \n",
       " -0.0306335   0.0136617   -0.0339053       0.0399674    0.00338514\n",
       " -0.030883    0.00418401   0.0294056       0.0444305   -0.0486901 \n",
       " -0.0315824   0.00510517   0.0136219       0.0163882   -0.0306642 \n",
       " -0.03162    -0.0183563   -0.0221163      -0.0434854    0.0115545 \n",
       " -0.031023    0.0271458   -0.0122713   …  -0.0478216    0.0332501 \n",
       " -0.0321558  -0.0372447   -0.0100942      -0.0360431   -0.0118828 \n",
       " -0.0315548   0.0552516   -0.04741         0.00986887  -0.0190811 \n",
       " -0.0319848   0.00100517   0.0108871       0.0349122   -0.0237772 \n",
       " -0.0320391   0.0270897    0.00419907     -0.0584444    0.0300926 ,\n",
       "\n",
       "[500.067,18.2038,18.0371,17.9469,17.8981,17.792,17.7471,17.7111,17.6353,17.602  …  0.124867,0.112387,0.0949634,0.0838646,0.0763925,0.0594904,0.0478936,0.0382033,0.0281761,0.00873282],\n",
       "1000x1000 Array{Float64,2}:\n",
       " -0.0322135   0.00159176   -0.00277963  …   0.010999      0.00425634\n",
       " -0.0313307   0.000441664   0.0172297       0.0739596     0.0165787 \n",
       " -0.0317067   0.0464951     0.0225618       0.000913603  -0.0039565 \n",
       " -0.0316716  -0.0681298     0.0111545       0.0221072     0.0385276 \n",
       " -0.0313728   0.0154032    -0.0971626      -0.000884029  -0.0191517 \n",
       " -0.0320758  -0.00356557   -0.0221612   …   0.0334739     0.112022  \n",
       " -0.0314876  -0.0927453    -0.0678757      -0.0168774     0.00165263\n",
       " -0.0316362  -0.0575995     0.0537223      -0.024613      0.0157039 \n",
       " -0.0323064   0.0250947    -0.0122391      -0.0492711    -0.0268793 \n",
       " -0.0313081  -0.0574475    -0.0187848       0.0108059     0.0413828 \n",
       " -0.0313682   0.0183131    -0.0152342   …   0.0562119     0.00749888\n",
       " -0.0303333  -0.0343073     0.0711252      -0.000109615   0.00475342\n",
       " -0.0314051  -0.0671007     0.0213975      -0.0287047    -0.0360852 \n",
       "  ⋮                                     ⋱                           \n",
       " -0.0315347  -0.018345     -0.0257471      -0.0415757     0.0308311 \n",
       " -0.0318514  -0.0349882    -0.015449       -0.0578713    -0.0511267 \n",
       " -0.0319375   0.0043436     0.00527623  …  -0.0211139     0.00234594\n",
       " -0.0325304   0.0185599    -0.0194278      -0.0288434     0.0779177 \n",
       " -0.0316012  -0.0142134     0.0209328      -0.0301348    -0.0469619 \n",
       " -0.0316241   0.0122844    -0.0108214      -0.0148955    -0.00538358\n",
       " -0.0322226   0.0361088     0.0653018      -0.000308181  -0.0523222 \n",
       " -0.0326107  -0.0136566     0.00579636  …   0.000497499  -0.0471113 \n",
       " -0.0312086  -0.0641714     0.0205916      -0.0123794     0.0109742 \n",
       " -0.0331914   0.0162244    -0.0472981      -0.0108841    -0.009811  \n",
       " -0.0316527   0.0269314    -0.0047998       0.030521      0.0332735 \n",
       " -0.0310981   0.00933591   -0.0417669      -0.0359394    -0.00884193)                                                                            \n",
       " (\n",
       "1000x1000 Array{Float64,2}:\n",
       " -0.0316742   0.0133352    0.0690014    …   0.011025      0.0335572  \n",
       " -0.0311683   0.00875399   0.00516719       0.0450326     0.0723881  \n",
       " -0.0311652   0.0330259    0.000611455      0.010652     -0.0735924  \n",
       " -0.0321694  -0.0139728    0.000789206     -0.000279067   0.0244743  \n",
       " -0.0310415  -0.0143442    0.00368245      -0.0095839     0.00572993 \n",
       " -0.0322922  -0.00941438   0.0682178    …  -0.0344233     0.0161699  \n",
       " -0.0317523   0.0290766   -0.0484861        0.0074016     0.0190238  \n",
       " -0.0318697  -0.0388748    0.0235967        0.000293481  -0.0228653  \n",
       " -0.0307828   0.00288349  -0.0437993        0.0243672    -0.0504049  \n",
       " -0.0319087  -0.0124359   -0.0162832        7.57735e-5   -0.000638359\n",
       " -0.032215    0.0289518   -0.0490708    …   0.050434      0.0138031  \n",
       " -0.0310621  -0.0094173   -0.0465291       -0.0933316     0.0169076  \n",
       " -0.0318591  -0.00286037  -0.0277179       -0.0688017     0.0553198  \n",
       "  ⋮                                     ⋱                            \n",
       " -0.031332   -0.0761597    0.0174579       -0.00173552   -0.0273398  \n",
       " -0.031163   -0.037718    -0.0341829       -0.0235745    -0.0561075  \n",
       " -0.031918   -0.0449337    0.00149095   …  -0.0382406     0.0252183  \n",
       " -0.0311726   0.055643     0.0598952       -0.00563334   -0.00254933 \n",
       " -0.0315303  -0.0204432    0.0257702       -0.0144664    -0.0260362  \n",
       " -0.0317664   0.0028352   -0.0501187       -0.0379457    -0.0706308  \n",
       " -0.0314343   0.0150337   -0.00508089      -0.0461069     0.00236515 \n",
       " -0.0315283  -0.0680254   -0.0302134    …  -0.0174229    -0.0460683  \n",
       " -0.0315663  -0.00326671  -0.0117204        0.0301        6.3492e-5  \n",
       " -0.0315926   0.0293577   -0.0131278        0.0266707     0.0712346  \n",
       " -0.0319065   0.0668894   -0.0190189       -0.0118277    -0.0165466  \n",
       " -0.0313485  -0.0413029    0.01193         -0.00232755   -0.000904978,\n",
       "\n",
       "[500.393,18.2235,17.9481,17.8871,17.8252,17.7927,17.7352,17.6434,17.6207,17.5731  …  0.139686,0.114952,0.110336,0.0891982,0.0704565,0.0579395,0.0439509,0.0237667,0.0140053,0.0063497],\n",
       "1000x1000 Array{Float64,2}:\n",
       " -0.0323971  -0.019804     0.0122853    …  -0.0415299   -0.0337334 \n",
       " -0.0316869   0.0717261    0.00247079       0.0365673    0.00322119\n",
       " -0.0316037  -0.00813614   0.0293037       -0.00806884   0.00833362\n",
       " -0.0318182   0.00435003   0.052725         0.0161566   -0.0952855 \n",
       " -0.0314181   0.00614265   0.0117191       -0.00910285   0.0216504 \n",
       " -0.0313496  -0.0103057   -0.00396766   …  -0.00815199  -0.0445661 \n",
       " -0.0316662  -0.0220428   -0.0319395        0.032139    -0.00930452\n",
       " -0.0314797  -0.0276505   -0.0347551        0.0245779    0.0377811 \n",
       " -0.0313735  -0.0278106    0.000578976     -0.0884256   -0.0163933 \n",
       " -0.032048   -0.0341336   -0.0144842       -0.00184892   0.00888547\n",
       " -0.0320024  -0.00208102  -0.0067106    …  -0.0144954   -0.016149  \n",
       " -0.0303233  -0.0567099    0.0268157        0.0591741   -0.00977062\n",
       " -0.0310098  -0.0331823   -0.0398185       -0.0124341   -0.0206787 \n",
       "  ⋮                                     ⋱                          \n",
       " -0.0318475  -0.00210586   0.0445142       -0.0561807    0.0281494 \n",
       " -0.0303687  -0.0182227    0.00750648      -0.0202667   -0.0364346 \n",
       " -0.0319894  -0.0292941    0.00611443   …  -0.0251062   -0.0680616 \n",
       " -0.0309075  -0.0194046    0.0758658       -0.0464734    0.00405091\n",
       " -0.0306355   0.0278935   -0.0253172        0.0342084   -0.00870195\n",
       " -0.0313635  -0.0100404    0.0114461        0.0138491    0.00321393\n",
       " -0.0312089  -0.0269243   -0.0251306       -0.0369785    0.0240726 \n",
       " -0.0312864  -0.0287158   -0.0427157    …   0.0130747   -0.00518499\n",
       " -0.0321317  -0.0021758   -0.0258771        0.0278179    0.00540127\n",
       " -0.0311823   0.00552868   0.0238407       -0.0259865   -0.0119136 \n",
       " -0.03212     0.022716    -0.0180176        0.0307461   -0.0292826 \n",
       " -0.0310157   0.041626    -0.00730649       0.0192799   -0.036322  )                        \n",
       " (\n",
       "1000x1000 Array{Float64,2}:\n",
       " -0.0313103  -0.00654472    0.0232018   …   0.014148     -0.00638094\n",
       " -0.032494    0.0612264     0.00858063      0.000706781   0.0197958 \n",
       " -0.0319192  -0.0155472    -0.0441549      -0.000518325   0.0143044 \n",
       " -0.0313091   0.0136935    -0.0435657       0.0244352     0.0437781 \n",
       " -0.0319251   7.95102e-5   -0.0430864      -0.00766091    0.0248205 \n",
       " -0.0314974  -0.0487074    -0.0227527   …  -0.0241266    -0.0447643 \n",
       " -0.031868    0.00825494   -0.0263624      -0.0342141     0.013869  \n",
       " -0.0310828   0.0160234     0.00581315     -0.0552734     0.0730481 \n",
       " -0.032524    0.0161058    -0.0216034       0.0115189     0.0115605 \n",
       " -0.0318202  -0.0524714    -0.0463726       0.0445718    -0.0154837 \n",
       " -0.0309111  -0.00846765    0.0199479   …   0.020984     -0.0526211 \n",
       " -0.0315168  -0.0269704     0.0144803      -0.0253552     0.0524088 \n",
       " -0.0315824  -0.0109065    -0.0136127       0.0173422    -0.0346089 \n",
       "  ⋮                                     ⋱                           \n",
       " -0.0318814  -0.00447242    0.0210847       0.0058284    -0.0163197 \n",
       " -0.0318218   0.0267268     0.0262059      -0.0394745    -0.0350299 \n",
       " -0.0315341   0.0189244     0.0288839   …  -0.0345313    -0.0117691 \n",
       " -0.0313643   0.03903      -0.0150623      -0.016677     -0.0130801 \n",
       " -0.0314724  -0.000999495  -0.0726285       0.0185769    -0.00630888\n",
       " -0.031472   -0.0040652    -0.0397396      -0.0435321    -0.0410513 \n",
       " -0.031696    0.00274857    0.0746628       0.0825487     0.039045  \n",
       " -0.0316337   0.00667949   -0.0313588   …   0.0348399     0.0168814 \n",
       " -0.0306343   0.0282756     0.0340377      -0.0613424    -0.013787  \n",
       " -0.0317294   0.0355864     0.0204791      -0.0137689    -0.033657  \n",
       " -0.0314863  -0.0148033    -0.0330459      -0.0257287     0.00569726\n",
       " -0.0309081   0.00145199   -0.0161258      -0.00774622    0.0019543 ,\n",
       "\n",
       "[500.07,18.3177,18.0657,17.9968,17.9511,17.8783,17.7254,17.6869,17.6507,17.5437  …  0.130419,0.118004,0.0887669,0.0715227,0.0668923,0.0493285,0.0404486,0.0230007,0.0121696,0.00457546],\n",
       "1000x1000 Array{Float64,2}:\n",
       " -0.0323215   0.0046697   -0.0604904    …   0.0058598     0.0133527 \n",
       " -0.0316767  -0.00832939   0.0312464        9.8159e-7    -0.0238586 \n",
       " -0.0310617  -0.0158523    0.00080219       0.034673     -0.0191501 \n",
       " -0.0308987  -0.0314435   -0.0089861       -0.0337042    -0.0265893 \n",
       " -0.0311711   0.0188564   -0.0215295       -0.0340563    -0.0388881 \n",
       " -0.0313024   0.0713723   -0.0492369    …   0.000369149  -0.0242741 \n",
       " -0.0313375  -0.0300517    0.0252754       -0.00528919    0.0325308 \n",
       " -0.0316665  -0.00667602  -0.0425922        0.00118308   -0.0382542 \n",
       " -0.0321321  -0.00622843  -0.0329253        0.00237012    0.0280785 \n",
       " -0.0319443   0.00677986  -0.0151098        0.124002      0.0173138 \n",
       " -0.0326735  -0.0325995    0.0509412    …   0.0102699     0.0562535 \n",
       " -0.0314319  -0.01813     -0.0102444        0.0246966    -0.00711401\n",
       " -0.0322092   0.00170078  -0.0508389       -0.0264247    -0.0154128 \n",
       "  ⋮                                     ⋱                           \n",
       " -0.0324738  -0.00133808  -0.00522284      -0.0578332    -0.00627328\n",
       " -0.0315814   0.0325167   -0.00261848       0.0384872     0.0274652 \n",
       " -0.0316801  -0.010338    -0.000382101  …  -0.0176569    -0.0126999 \n",
       " -0.032174   -0.0251472   -0.0434373       -0.0100413     0.0495711 \n",
       " -0.0311594   0.00413731  -0.00230771       0.0018824    -0.0161502 \n",
       " -0.0310629   0.0240398    0.0152629       -0.0115553     0.00728717\n",
       " -0.0311931   0.0561461   -0.0320042        0.000420811  -0.00861563\n",
       " -0.0314455   0.0159121    0.0159869    …   0.0268653    -0.00801381\n",
       " -0.0316997   0.0230297   -0.00270103       0.0153495    -0.0518636 \n",
       " -0.032134    0.024718    -0.0264364       -0.00153078   -0.0479481 \n",
       " -0.0324275  -0.03345     -0.0349998       -0.0563842     0.0125677 \n",
       " -0.0315684   0.00935097   0.0194398        0.0629849    -0.00549577)                       \n",
       " (\n",
       "1000x1000 Array{Float64,2}:\n",
       " -0.0318711   0.00805696   -0.0480637    …  -0.0263535    0.0643412 \n",
       " -0.0311581  -0.00765909   -0.0508839        0.0243035   -0.0650702 \n",
       " -0.0322328  -0.00150308    0.0427082       -0.0426653   -0.0219997 \n",
       " -0.0312797   0.0171424     0.0159806       -0.0572747   -0.0161803 \n",
       " -0.0319439  -0.00941684    0.0157746       -0.0280482   -0.00169979\n",
       " -0.0314744   0.0112993    -0.0229107    …   0.00432614  -0.0453518 \n",
       " -0.0307109   0.0216907    -0.0344932       -0.00614394   0.034677  \n",
       " -0.0317127   0.0285976    -0.0254382       -0.00369774   0.0718086 \n",
       " -0.031273   -0.0455377    -0.0119652        0.00994258   0.0458068 \n",
       " -0.0314815   0.0440214    -0.0188127       -0.0515394   -0.00788544\n",
       " -0.0321459   0.0177682     0.0537503    …   0.0514284    0.010644  \n",
       " -0.0310081  -0.00530729    0.0257753        0.0149043    0.033315  \n",
       " -0.0311187  -0.00110058    0.000869105      0.0521005   -0.0548737 \n",
       "  ⋮                                      ⋱                          \n",
       " -0.0322764  -0.0129767    -0.00620114      -0.0242401   -0.0262943 \n",
       " -0.0311549  -0.0461249    -0.0162866        0.0304655   -0.00806029\n",
       " -0.0315172   0.0484705     0.0537086    …   0.0310412   -0.0145127 \n",
       " -0.0313789  -0.0433694    -0.0267059       -0.00112547  -0.0446374 \n",
       " -0.031019   -0.00932382    0.0242568        0.0211282   -0.0703968 \n",
       " -0.032305    0.00237796    0.0104905       -0.0253304   -0.0677107 \n",
       " -0.0322402  -0.000537845  -0.00865849       0.0406577   -0.0016998 \n",
       " -0.0317196  -0.0414265    -0.0470206    …  -0.0396345    0.0309912 \n",
       " -0.031637   -0.0198547     0.0415703        0.0141807    0.00644777\n",
       " -0.0324679   0.0766867    -0.0231011        0.0287489    0.00722737\n",
       " -0.0317849   0.0321807     0.0148137       -0.0253065   -0.0256928 \n",
       " -0.0314195  -0.00171852    0.0127046        0.0407049    0.0399023 ,\n",
       "\n",
       "[500.245,18.1703,18.1023,17.9333,17.8339,17.7536,17.6742,17.6659,17.6064,17.568  …  0.121678,0.111591,0.105031,0.0799438,0.068434,0.062672,0.0498136,0.0315141,0.0201857,0.00639745],\n",
       "1000x1000 Array{Float64,2}:\n",
       " -0.0315337   0.00740407  -0.0243968    …  -0.0462548   -0.0240054 \n",
       " -0.0319597  -0.0199967    0.0347326       -0.0534377    0.0173708 \n",
       " -0.0309367  -0.0214384   -0.059438        -0.00904282   0.0310046 \n",
       " -0.0326446   0.0106368   -0.0283319       -0.0812897    0.056655  \n",
       " -0.0301924   0.0221773   -0.0150877        0.0121352    0.0018212 \n",
       " -0.0314182  -0.0106393   -0.00139447   …   0.0138019   -0.00528798\n",
       " -0.0310204   0.0132042    0.009797         0.0298461   -0.0213781 \n",
       " -0.0315759  -0.0533861   -0.0102707       -0.0415492   -0.0184072 \n",
       " -0.0319066   0.0217607   -0.0560619        0.0547258    0.0170306 \n",
       " -0.0321263  -0.0177006    0.0123787       -0.014285    -0.0439551 \n",
       " -0.0312619   0.0018398   -0.000146243  …  -0.0321149    0.010872  \n",
       " -0.0317229  -0.00255452   0.060842         0.0120574    0.00605955\n",
       " -0.0310997   0.0517467   -0.0156236       -0.0344767   -0.0157497 \n",
       "  ⋮                                     ⋱                          \n",
       " -0.0316006  -0.00346457   0.0157845        0.0561398   -0.00542239\n",
       " -0.0325761   0.0244137   -0.00558137       0.0229194   -0.0217075 \n",
       " -0.032504    0.0245811    0.0145313    …   0.0350604   -0.012603  \n",
       " -0.0324605  -0.0386595   -0.0519366        0.0638144    0.0397181 \n",
       " -0.0308784   0.0296649    0.0186231       -0.0102554    0.0408453 \n",
       " -0.0310478  -0.00560497  -0.0766063       -0.0209058   -0.00962382\n",
       " -0.0313773   0.0149166   -0.0317488        0.0229147   -0.0373831 \n",
       " -0.0314047   0.0196051    0.0107712    …   0.0135458   -0.0366481 \n",
       " -0.0311971  -0.0313826   -0.0558892       -0.0266967   -0.0105156 \n",
       " -0.0308406  -0.00836099   0.0171308        0.0720033   -0.0281147 \n",
       " -0.0322703  -0.0235145   -0.00141545      -0.0302422    0.0674788 \n",
       " -0.0313456   0.0143972    0.0311205        0.0173958   -0.0285275 )                                                    \n",
       " (\n",
       "1000x1000 Array{Float64,2}:\n",
       " -0.0313983   0.0207022   -0.0055052   …   0.0226979    0.0517453 \n",
       " -0.0314834  -0.0223501    0.00396015      0.0171947    0.00227511\n",
       " -0.0316995  -0.026657    -0.00554984      0.028354     0.0527908 \n",
       " -0.0313885   0.022713    -0.028284        0.0376386   -0.0590775 \n",
       " -0.0324213   0.028        0.0164005      -0.0163999    0.0185516 \n",
       " -0.0312068   0.047732    -0.0473609   …  -0.0211494   -0.0310258 \n",
       " -0.0316333   0.0122893    0.0143514       0.0518656    0.0168077 \n",
       " -0.0313218   0.00794023   0.018072        0.0309595   -0.0155998 \n",
       " -0.0310841  -0.00719546   0.0390157      -0.0107155   -0.0302309 \n",
       " -0.031279   -0.0164453   -0.00142131      0.00348101   0.0310096 \n",
       " -0.0322281  -0.0360295    0.014       …  -0.048226     0.0221374 \n",
       " -0.0317016   0.00517955   0.00973832     -0.0700627   -0.00744733\n",
       " -0.0319883   0.025996    -0.00826132     -0.0452517   -0.0594304 \n",
       "  ⋮                                    ⋱                          \n",
       " -0.0309215  -0.00596426  -0.00819372      0.0268047   -0.0461233 \n",
       " -0.0311933  -0.0192625   -0.0117496       0.0102788    0.0386931 \n",
       " -0.0305746  -0.0147678   -0.052843    …   0.0122167   -0.012118  \n",
       " -0.0323169   0.0570554    0.0697525      -0.0154428    0.0307955 \n",
       " -0.0304591   0.0203      -0.0203509      -0.0535934   -0.0288091 \n",
       " -0.0320544   0.0185867   -0.0250957       0.0218188    0.00668421\n",
       " -0.0320508  -0.0285497   -0.0135095       0.0454763    0.00130004\n",
       " -0.0320282  -0.0411153   -0.00779455  …   0.0376908    0.0221182 \n",
       " -0.0318897   0.00804967   0.0153071      -0.00594068  -0.0122297 \n",
       " -0.0316086   0.0471243    0.0106773       0.0607075   -0.0308945 \n",
       " -0.0314557   0.0221995   -0.0284412      -0.0683159   -0.0247252 \n",
       " -0.030863    0.0556676    0.0371675      -0.0409062   -0.0288518 ,\n",
       "\n",
       "[500.321,18.181,18.0505,17.9344,17.898,17.8245,17.7573,17.6777,17.6014,17.5441  …  0.156115,0.12965,0.0971935,0.0944057,0.0694325,0.0631605,0.0443681,0.0266521,0.0104378,0.00346263],\n",
       "1000x1000 Array{Float64,2}:\n",
       " -0.0317875   0.0471097    -0.00295984  …  -0.00869957  -0.0133237 \n",
       " -0.0317651   0.0175946    -0.00350022     -0.0153195    0.0684645 \n",
       " -0.0319868  -0.0375753    -0.0333957       0.00730299   0.0336145 \n",
       " -0.0321155   0.0363559    -0.00378868      0.00667307   0.0315361 \n",
       " -0.0319453  -0.00974674   -0.0174119       0.0241573    0.0630485 \n",
       " -0.0317155  -0.000510777  -0.0791593   …  -0.0223518    0.0286323 \n",
       " -0.0323415   0.00328858   -0.0234512      -0.0196757    0.0136216 \n",
       " -0.0320037   0.0839315     0.0388716      -0.0197626   -0.00091601\n",
       " -0.0313539   0.000998398   0.00486185      0.00184992   0.0254469 \n",
       " -0.0318889  -0.0614657     0.0385123      -0.00376092   0.00523793\n",
       " -0.0318812   0.0510955    -0.0336364   …   0.0290682   -0.0431204 \n",
       " -0.0305451   0.0683755     0.0156913       0.00183959  -0.0182877 \n",
       " -0.0315011  -0.00415316   -0.00260902     -0.0334304   -0.0212339 \n",
       "  ⋮                                     ⋱                          \n",
       " -0.0317028   0.00289791   -0.00734486     -0.0175891    0.0370482 \n",
       " -0.0314042  -0.0177879    -0.00409227      0.0613305   -0.00554942\n",
       " -0.0320101  -0.0338723     0.0325182   …   0.0436543   -0.0333089 \n",
       " -0.0316752  -0.0701275    -0.0217455       0.0288082    0.0018414 \n",
       " -0.0318266  -0.0432967     0.0250375       0.0280274   -0.0392404 \n",
       " -0.0311565  -0.00477509    0.003031       -0.0268792   -0.0216355 \n",
       " -0.0322985   0.0529426    -0.0111843      -0.018867    -0.0608454 \n",
       " -0.0309273   0.0194525    -0.0737109   …  -0.0266395   -0.0374482 \n",
       " -0.0324693  -0.0397818    -0.00849708      0.0120955   -0.0270653 \n",
       " -0.0318806  -0.0137879     0.0393443      -0.0226053   -0.0311311 \n",
       " -0.0320795  -0.0345222     0.00283574     -0.0654261    0.0203869 \n",
       " -0.0312096  -0.00564373   -0.0200581      -0.0121886    0.0272924 )                                                                                                       \n",
       " (\n",
       "1000x1000 Array{Float64,2}:\n",
       " -0.0320206  -0.0089758     0.000502019  …  -0.0131309    -0.0477539 \n",
       " -0.0314596  -0.017347      0.0294323       -0.0363836     0.0273141 \n",
       " -0.0318783  -0.0107089    -0.0348978        0.0498776    -0.0044475 \n",
       " -0.0309504  -0.0804055    -0.0182298        0.0291982     0.0103861 \n",
       " -0.0322564  -0.00318544    0.0171213        0.0555446    -0.0670248 \n",
       " -0.0307806   0.0178743     0.016444     …  -0.0293933    -0.00711265\n",
       " -0.031443    0.022308      0.00854311       0.0347318    -0.0342855 \n",
       " -0.0320006   0.00820901    0.00411599      -0.0404357    -0.0285995 \n",
       " -0.0310788  -0.0396377     0.0511615        0.0179447    -0.013625  \n",
       " -0.03101     0.0117374     0.0251036       -0.0609646     0.00295707\n",
       " -0.0320174  -0.0031705     0.015451     …  -0.00361907    0.00786946\n",
       " -0.031203   -0.018154     -0.0413482       -0.0143969     0.044221  \n",
       " -0.0309658   0.00142843   -0.0494183        0.0403491     0.0135499 \n",
       "  ⋮                                      ⋱                           \n",
       " -0.0320566   0.0182308    -0.000800792     -0.0140785     0.00450973\n",
       " -0.0321562   0.00496867    0.00955546      -0.0141052    -0.00861834\n",
       " -0.0319402  -0.0266798     0.00699837   …   0.000106863  -0.0102904 \n",
       " -0.0316157  -0.0106662    -0.0120287        0.0293757     0.037387  \n",
       " -0.0324989   0.00712198   -0.0273992       -0.0329815    -0.0171051 \n",
       " -0.0322805   0.0363943    -0.00984008       0.0507507     0.0322282 \n",
       " -0.0306987   0.0336603    -0.0367372       -0.0200794     0.0344693 \n",
       " -0.0322965   0.0203074     0.0204259    …   0.0369977     0.032771  \n",
       " -0.0318243  -0.0307868    -0.00341934      -0.0137891    -0.00259121\n",
       " -0.0327057   0.000389455  -0.00171509       0.00959172    0.0104363 \n",
       " -0.0317213   0.00698544   -0.0172345        0.00346828    0.0295164 \n",
       " -0.0310285   0.0479227    -0.00106766       0.0109743    -0.0234314 ,\n",
       "\n",
       "[500.442,18.0878,17.9036,17.85,17.7784,17.741,17.6732,17.6608,17.6067,17.5366  …  0.136784,0.111486,0.10281,0.0868323,0.0778595,0.0627772,0.0598781,0.0283203,0.0131372,0.000861846],\n",
       "1000x1000 Array{Float64,2}:\n",
       " -0.0310477  -0.0422837    0.00734554   …  -0.0239202    -0.029389  \n",
       " -0.0306813   0.0184844    0.000406712      0.0105943    -0.048032  \n",
       " -0.0317307  -0.0404743    0.0368213       -0.00109987   -0.0160552 \n",
       " -0.0321309   0.0188876   -0.0440159       -0.000633591  -0.0595851 \n",
       " -0.0314003  -0.0137317    0.0312613        0.0180577    -0.0548753 \n",
       " -0.0310507   0.00535978  -0.0334515    …  -0.0303517    -0.0258753 \n",
       " -0.0323151  -0.0768978   -0.00399152      -0.0119047     0.00578381\n",
       " -0.0310891   0.0420879   -0.00175882       0.0291853     0.0234839 \n",
       " -0.0321265  -0.0100029   -0.0319528        0.0297878    -0.071327  \n",
       " -0.032419    0.0279999    0.0221839        0.0688604     0.0290567 \n",
       " -0.031819   -0.00552401  -0.0192874    …   0.00393955    0.0253776 \n",
       " -0.0311273   0.0118443    0.0259216       -0.00433602    0.0399149 \n",
       " -0.0314836  -0.00971391  -0.0384086        0.00307012    0.00872351\n",
       "  ⋮                                     ⋱                           \n",
       " -0.0304155  -0.0213964   -0.013749         0.0221127    -0.0242921 \n",
       " -0.0308451  -0.0503676   -0.0133873        0.013527      0.00210509\n",
       " -0.0318423  -0.0295342   -0.0144618    …  -0.0300665     0.0376749 \n",
       " -0.0315525   0.00999213  -0.0340122        0.00517422    0.019973  \n",
       " -0.0318201   0.00171744   0.0382823       -0.031971     -0.0174228 \n",
       " -0.0313731   0.0537227    0.00235029      -0.0178175    -0.022608  \n",
       " -0.0316823   0.0463977    0.00392586      -0.0398985     0.00361874\n",
       " -0.0315631  -0.0238631   -0.0054913    …   0.0283301     0.0172016 \n",
       " -0.0313477  -0.0356621    0.0541013        0.0478828    -0.0357583 \n",
       " -0.0320047   0.054402    -0.0487756        0.0108888    -0.0352822 \n",
       " -0.0315672  -0.038902     0.00345088       0.0112731     0.0248229 \n",
       " -0.0312429  -0.00225537   0.000547145     -0.0185298     0.0478664 )\n",
       " (\n",
       "1000x1000 Array{Float64,2}:\n",
       " -0.0323357   0.0221509    -0.0526412   …   0.0201623     0.00696258\n",
       " -0.0310968   0.00290013    0.0332939      -0.0122061    -0.0186167 \n",
       " -0.0324101  -0.0332535    -0.031153        0.00674823    0.0292135 \n",
       " -0.0315218  -0.0675527     0.0066112      -0.0205861    -0.00758214\n",
       " -0.0317544   0.0177152    -0.00458172      0.0310801     0.00849678\n",
       " -0.0312928   0.0423726     0.0449908   …  -0.0421133     0.0298728 \n",
       " -0.0315021   0.0618166    -0.00884772     -0.000674594   0.0034676 \n",
       " -0.0315466  -0.0527486     0.0121004      -0.0124539    -0.0101208 \n",
       " -0.0316488   0.00827793   -0.00247849     -0.0146089    -0.0297506 \n",
       " -0.0312519   0.0377762     0.0396419      -0.030673      0.0449258 \n",
       " -0.0310857  -0.0153248     0.0147796   …   0.02401      -0.00637954\n",
       " -0.0311531  -0.00919443    0.0341344      -0.000373942  -0.00786406\n",
       " -0.031492   -0.00997172    0.0516605      -0.0162703    -0.0595931 \n",
       "  ⋮                                     ⋱                           \n",
       " -0.0322688   0.000986941   0.0471894      -0.00535209    0.0100576 \n",
       " -0.0313299  -0.0439111     0.0124698      -0.0241713    -0.00626812\n",
       " -0.030482   -0.0164279    -0.00514223  …   0.0173929     0.0313134 \n",
       " -0.0313018   0.0706865     0.0047833       0.052498      0.021586  \n",
       " -0.0316512  -0.0107718    -0.105356       -0.021864      0.033522  \n",
       " -0.0320653  -0.0166917    -0.0376717      -0.0344816    -0.0439615 \n",
       " -0.0315346   0.0295491     0.0420079      -0.0218553     0.0252366 \n",
       " -0.030643   -0.00999785    0.00499473  …   0.0167872    -0.0443659 \n",
       " -0.0315505   0.00366892   -0.0383638       0.0154938     0.0307068 \n",
       " -0.0317362   0.0115278     0.0182906      -0.0120225    -0.0342313 \n",
       " -0.0318841  -0.0228648     0.0590071       0.00592778   -0.0696986 \n",
       " -0.0327502  -0.00898135   -0.0257754      -0.00592045    0.0230224 ,\n",
       "\n",
       "[500.007,18.1359,17.9385,17.8959,17.8611,17.7391,17.7121,17.6883,17.6336,17.5897  …  0.119142,0.115771,0.0893288,0.0766316,0.0612852,0.048867,0.0370283,0.0351352,0.0187093,0.00680023],\n",
       "1000x1000 Array{Float64,2}:\n",
       " -0.0322955   0.00119357   -0.0243035   …  -0.0227516   -0.0121238 \n",
       " -0.032971   -0.0800886    -0.0698668      -0.0348376   -0.0238516 \n",
       " -0.03195    -0.0537429    -0.0584575       0.00896812  -0.0121454 \n",
       " -0.032239   -0.0065838    -0.0196659       0.0119562   -0.0231176 \n",
       " -0.0325748  -0.0309026    -0.0448319      -0.00174992   0.045656  \n",
       " -0.0308427   0.0187781    -0.057677    …   0.0514889    0.00401818\n",
       " -0.0305522  -0.0112776    -0.0539562      -0.00645983  -0.0296273 \n",
       " -0.032046   -0.0146263    -0.0349177       0.0103019   -0.0324972 \n",
       " -0.0310646   0.0897599     0.00122506      0.00921706   0.00301892\n",
       " -0.0320768  -0.00169417    0.0302692      -0.0173668   -0.0202389 \n",
       " -0.0318762  -0.0202933     0.0172769   …  -0.0546352    0.0294239 \n",
       " -0.0319001  -0.0210667     0.0560677       0.0479624    0.0213666 \n",
       " -0.0312647  -0.0498571     0.0159029       0.0394486    0.0222858 \n",
       "  ⋮                                     ⋱                          \n",
       " -0.0315633  -0.0600609    -0.0271722       0.0531922    0.020346  \n",
       " -0.0311739  -0.0287136     0.0762643      -0.0558777    0.0262713 \n",
       " -0.0323909  -0.0515567     0.0402287   …   0.0122158   -0.00730309\n",
       " -0.032061    0.0366136    -0.0131001       0.0182199   -0.0116899 \n",
       " -0.0303308  -0.0126467     0.00137868      0.0212807   -0.0297874 \n",
       " -0.0308367  -0.0711133    -0.0277149      -0.035673    -0.012492  \n",
       " -0.0319187  -0.00153539    0.0307764       0.00933752  -0.0328619 \n",
       " -0.0318414  -0.0143061    -0.0236149   …  -0.0320921    0.0229836 \n",
       " -0.0321053   0.0585957     0.00319534     -0.0797821    0.0603332 \n",
       " -0.0322764  -0.000890043  -0.0790576      -0.00331492  -0.0163157 \n",
       " -0.0313317  -0.0085886    -0.0217407      -0.00376247   0.0119448 \n",
       " -0.033249   -0.0278551    -0.0182775      -0.0213252    0.0265923 )                                                 \n",
       " (\n",
       "1000x1000 Array{Float64,2}:\n",
       " -0.0321836  -0.00297745    0.0111187   …  -0.0337682   -0.0182998 \n",
       " -0.0308504   0.0248013     0.0148731      -0.0252999   -0.0471536 \n",
       " -0.0325281   0.0395512     0.0297088      -0.00022007  -0.0362721 \n",
       " -0.0307975   0.0322079     0.00908688     -0.0456193   -0.0230697 \n",
       " -0.0314328  -0.0187266    -0.0595569      -0.00282989   0.0313624 \n",
       " -0.031832    0.00260467   -0.0243129   …  -0.0170886    0.0478207 \n",
       " -0.0319826   0.0113779     0.00822741      0.0290871   -0.00869156\n",
       " -0.0312552   0.0333114     0.0194111       0.065326     0.0060968 \n",
       " -0.0316926  -0.0451339    -0.0384118      -0.0177176    0.00381441\n",
       " -0.0320891  -0.0506606    -0.00506552     -0.0145112    0.0160023 \n",
       " -0.0330957   0.0108475    -0.00624669  …   0.0135705   -0.020802  \n",
       " -0.0323914  -0.00855534   -0.00955634      0.0161693   -0.0337319 \n",
       " -0.031605    0.0325389    -0.0432339       0.0607388   -0.0105273 \n",
       "  ⋮                                     ⋱                          \n",
       " -0.0313625   0.0111191     0.0698121      -0.0312024   -0.0324048 \n",
       " -0.0320718  -0.0391466    -0.00594814     -0.0541554   -0.0436086 \n",
       " -0.031523   -0.000152669  -0.0119542   …   0.010718    -0.0283745 \n",
       " -0.0314384   0.022198     -0.0314677      -0.0200211   -0.0402655 \n",
       " -0.0325266  -0.0243512     0.00420992     -0.0462169   -0.0600497 \n",
       " -0.0307989   0.00870659   -0.0348654      -0.0163026   -0.0184254 \n",
       " -0.0319537   0.0138771     0.00553334      0.00332206   0.0435255 \n",
       " -0.0326789  -0.0197221     0.0350814   …  -0.0502508    0.0753324 \n",
       " -0.0311312  -0.0273051    -0.0339983      -0.017892    -0.0291703 \n",
       " -0.0312967   0.0428873     0.0292752      -0.0176499    0.00114455\n",
       " -0.0305234   0.0273568     0.0325067       0.0115195   -0.0308264 \n",
       " -0.0319621   0.0439981    -0.0400634      -0.0199784    0.0226343 ,\n",
       "\n",
       "[500.618,18.3127,18.1638,18.0177,17.9535,17.9021,17.7955,17.745,17.6996,17.5864  …  0.126605,0.118031,0.107663,0.0941558,0.0903263,0.0464589,0.0393581,0.0291049,0.0198956,0.00311996],\n",
       "1000x1000 Array{Float64,2}:\n",
       " -0.0318578   0.0204752   -0.00259606   …   0.0537378     0.0128961  \n",
       " -0.0312428  -0.0561763    0.0646875       -0.000457539   0.0284767  \n",
       " -0.0314256  -0.0628404    0.0603249       -0.0102337     0.0401459  \n",
       " -0.0312844   0.0288765    0.0120206       -0.0471644     0.0103918  \n",
       " -0.0317169   0.0407339    0.0119454        0.0390132    -0.000723993\n",
       " -0.0313529  -0.014059     0.0132301    …  -0.0143319    -0.00873342 \n",
       " -0.0307497   0.0347104    0.0246775       -0.000547225  -0.0165542  \n",
       " -0.0315722   0.0204099   -0.0216212       -0.0306536    -0.0119713  \n",
       " -0.0306945  -0.0323832    0.0211347        0.0678719     0.0127193  \n",
       " -0.0307669  -0.032466     0.016163         0.0298962     0.0386185  \n",
       " -0.0323766  -0.0161015    0.0320944    …  -0.0200903    -0.00446966 \n",
       " -0.0313843   0.0157253   -0.00443882       0.012719      0.00390969 \n",
       " -0.0326451   0.073238     0.00368126       0.0354305     0.0639259  \n",
       "  ⋮                                     ⋱                            \n",
       " -0.031067   -0.055187    -0.0206122        0.036984      0.0202349  \n",
       " -0.030995   -0.0144559    0.000107196     -0.0121713     0.0183217  \n",
       " -0.0319696   0.0137264   -0.00490151   …   0.0288551     0.0100012  \n",
       " -0.0316169  -0.034485    -0.0242088        0.00759825    0.0216443  \n",
       " -0.0313676  -0.0299706   -0.0357974        0.00434088    0.0230899  \n",
       " -0.0313323   0.0250718   -0.00571447      -0.0179489    -0.0373981  \n",
       " -0.0316393  -0.0216792    0.0155216        0.0228069     0.0150528  \n",
       " -0.0311551   0.0829593    0.00214394   …  -0.0323333     0.0367447  \n",
       " -0.0321172   0.0411034   -0.00270131       0.000343015   0.0123599  \n",
       " -0.0312701   0.0516698   -0.0408235       -0.0238943    -0.0309582  \n",
       " -0.0318623  -0.0124982    0.0486201       -0.0591437     0.00963327 \n",
       " -0.0329565   0.00959101  -0.0339874       -0.0210767     0.0204057  )                        "
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "M = Matrix{Float64}[rand(1000,1000) for i=1:10]\n",
    "pmap(svd, M)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{verbatim}\n",
       "..  pmap(f, lsts...; err_retry=true, err_stop=false, pids=workers())\n",
       "\n",
       "Transform collections ``lsts`` by applying ``f`` to each element in parallel.\n",
       "(Note that ``f`` must be made available to all worker processes; see :ref:`Code Availability and Loading Packages <man-parallel-computing-code-availability>` for details.)\n",
       "If ``nprocs() > 1``, the calling process will be dedicated to assigning tasks.\n",
       "All other available processes will be used as parallel workers, or on the processes specified by ``pids``.\n",
       "\n",
       "If ``err_retry`` is ``true``, it retries a failed application of ``f`` on a different worker.\n",
       "If ``err_stop`` is ``true``, it takes precedence over the value of ``err_retry`` and ``pmap`` stops execution on the first error.\n",
       "\\end{verbatim}\n"
      ],
      "text/markdown": [
       "```rst\n",
       "..  pmap(f, lsts...; err_retry=true, err_stop=false, pids=workers())\n",
       "\n",
       "Transform collections ``lsts`` by applying ``f`` to each element in parallel.\n",
       "(Note that ``f`` must be made available to all worker processes; see :ref:`Code Availability and Loading Packages <man-parallel-computing-code-availability>` for details.)\n",
       "If ``nprocs() > 1``, the calling process will be dedicated to assigning tasks.\n",
       "All other available processes will be used as parallel workers, or on the processes specified by ``pids``.\n",
       "\n",
       "If ``err_retry`` is ``true``, it retries a failed application of ``f`` on a different worker.\n",
       "If ``err_stop`` is ``true``, it takes precedence over the value of ``err_retry`` and ``pmap`` stops execution on the first error.\n",
       "```\n"
      ],
      "text/plain": [
       "```rst\n",
       "..  pmap(f, lsts...; err_retry=true, err_stop=false, pids=workers())\n",
       "\n",
       "Transform collections ``lsts`` by applying ``f`` to each element in parallel.\n",
       "(Note that ``f`` must be made available to all worker processes; see :ref:`Code Availability and Loading Packages <man-parallel-computing-code-availability>` for details.)\n",
       "If ``nprocs() > 1``, the calling process will be dedicated to assigning tasks.\n",
       "All other available processes will be used as parallel workers, or on the processes specified by ``pids``.\n",
       "\n",
       "If ``err_retry`` is ``true``, it retries a failed application of ``f`` on a different worker.\n",
       "If ``err_stop`` is ``true``, it takes precedence over the value of ``err_retry`` and ``pmap`` stops execution on the first error.\n",
       "```\n"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@doc pmap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{verbatim}\n",
       "svd(A, B) -> U, V, Q, D1, D2, R0\n",
       "\\end{verbatim}\n",
       "Wrapper around \\texttt{svdfact} extracting all parts the factorization to a tuple. Direct use of \\texttt{svdfact} is therefore generally more efficient. The function returns the generalized SVD of \\texttt{A} and \\texttt{B}, returning \\texttt{U}, \\texttt{V}, \\texttt{Q}, \\texttt{D1}, \\texttt{D2}, and \\texttt{R0} such that \\texttt{A = U*D1*R0*Q'} and \\texttt{B = V*D2*R0*Q'}.\n",
       "\\begin{verbatim}\n",
       "svd(A, [thin=true]) -> U, S, V\n",
       "\\end{verbatim}\n",
       "Wrapper around \\texttt{svdfact} extracting all parts the factorization to a tuple. Direct use of \\texttt{svdfact} is therefore generally more efficient. Computes the SVD of \\texttt{A}, returning \\texttt{U}, vector \\texttt{S}, and \\texttt{V} such that \\texttt{A == U*diagm(S)*V'}. If \\texttt{thin} is \\texttt{true}, an economy mode decomposition is returned. The default is to produce a thin decomposition.\n"
      ],
      "text/markdown": [
       "```\n",
       "svd(A, B) -> U, V, Q, D1, D2, R0\n",
       "```\n",
       "\n",
       "Wrapper around `svdfact` extracting all parts the factorization to a tuple. Direct use of `svdfact` is therefore generally more efficient. The function returns the generalized SVD of `A` and `B`, returning `U`, `V`, `Q`, `D1`, `D2`, and `R0` such that `A = U*D1*R0*Q'` and `B = V*D2*R0*Q'`.\n",
       "\n",
       "```\n",
       "svd(A, [thin=true]) -> U, S, V\n",
       "```\n",
       "\n",
       "Wrapper around `svdfact` extracting all parts the factorization to a tuple. Direct use of `svdfact` is therefore generally more efficient. Computes the SVD of `A`, returning `U`, vector `S`, and `V` such that `A == U*diagm(S)*V'`. If `thin` is `true`, an economy mode decomposition is returned. The default is to produce a thin decomposition.\n"
      ],
      "text/plain": [
       "```\n",
       "svd(A, B) -> U, V, Q, D1, D2, R0\n",
       "```\n",
       "\n",
       "Wrapper around `svdfact` extracting all parts the factorization to a tuple. Direct use of `svdfact` is therefore generally more efficient. The function returns the generalized SVD of `A` and `B`, returning `U`, `V`, `Q`, `D1`, `D2`, and `R0` such that `A = U*D1*R0*Q'` and `B = V*D2*R0*Q'`.\n",
       "\n",
       "```\n",
       "svd(A, [thin=true]) -> U, S, V\n",
       "```\n",
       "\n",
       "Wrapper around `svdfact` extracting all parts the factorization to a tuple. Direct use of `svdfact` is therefore generally more efficient. Computes the SVD of `A`, returning `U`, vector `S`, and `V` such that `A == U*diagm(S)*V'`. If `thin` is `true`, an economy mode decomposition is returned. The default is to produce a thin decomposition.\n"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@doc svd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Julia 0.4.5",
   "language": "julia",
   "name": "julia-0.4"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "0.4.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
